本文整理汇总了Python中PyQt4.QtGui.QGraphicsSimpleTextItem.setX方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsSimpleTextItem.setX方法的具体用法?Python QGraphicsSimpleTextItem.setX怎么用?Python QGraphicsSimpleTextItem.setX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsSimpleTextItem
的用法示例。
在下文中一共展示了QGraphicsSimpleTextItem.setX方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setX [as 别名]
def __init__(self, table, vector, mass=1.0):
"""Documentation here"""
self.name = table.name
self._mediator = Mediator()
# layout widget
x, y = vector.x, vector.y
text = QGraphicsSimpleTextItem('{0} as {1}'.format(self.name, self.alias))
width = text.boundingRect().width()
QGraphicsRectItem.__init__(self, x, y, width + 10, 22)
self.table = table.alias(self.alias)
self.setBrush(Qt.cyan)
self.setPen(Qt.darkCyan)
self.width = width + 10
self.height = 22
self.setFlag(self.ItemIsSelectable, True)
text.setParentItem(self)
text.setX(x + 5)
text.setY(y + 5)
self.point = vector
self.mass = mass
self.velocity = Vector(0, 0)
self.force = Vector(0, 0)
self.instances.append(self)
示例2: update_items
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setX [as 别名]
def update_items(self):
self.item = QGraphicsRectItem(
0, 0, self.width, self.row_h * self.coeff_h)
seq_width = 0
nopen = QPen(Qt.NoPen)
self.item.setPen(nopen)
font = QFont(self.ftype, self.fsize)
if self.fstyle == "italic":
font.setStyle(QFont.StyleItalic)
elif self.fstyle == "oblique":
font.setStyle(QFont.StyleOblique)
rect_cls = QGraphicsRectItem
for i, val in enumerate(self.liste):
width = self.col_w
height = self.row_h * len(str(val)) + 1
rectitem = rect_cls(0, 0, width, height, parent=self.item)
rectitem.setX(seq_width) # to give correct X to children item
rectitem.setBrush(QBrush(QColor(self.bgcolor)))
rectitem.setPen(nopen)
# write letter if enough space in height
if height >= self.fsize:
text = QGraphicsSimpleTextItem(str(val), parent=rectitem)
text.setFont(font)
text.setBrush(QBrush(QColor(self.fgcolor)))
# Center text according to rectitem size
# txtw = text.boundingRect().width()
txth = text.boundingRect().height()
text.setRotation(self.rot)
text.setX(txth)
seq_width += width
self.width = seq_width
示例3: display_answer
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setX [as 别名]
def display_answer(self, question, answers, correct_answer, description, selected_index, correct):
x, y = self.display_question(question, answers, selected_index, correct) #TODO pass what to check and if right or wrong
y += 50
item = QGraphicsSimpleTextItem("Correct Answer: %s" % correct_answer)
item.setBrush(self.TEXT_COLOR)
font = QFont(self.BOLDISH)
font.setUnderline(True)
item.setFont(font)
item.setX(x)
item.setY(y)
self.qtscene.addItem(item)
self.references.append(item)
y += 60
item = QGraphicsSimpleTextItem(make_pretty(description, 55))
item.setBrush(self.TEXT_COLOR)
item.setFont(self.NORMALISH)
item.setX(x)
item.setY(y)
self.qtscene.addItem(item)
self.references.append(item)
item = QPushButton('Next')
item.clicked.connect(self.on_next)
item.setFont(self.BOLDISH)
item.move(x+700, y)
self.qtscene.addWidget(item)
self.references.append(item)
示例4: display_question
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setX [as 别名]
def display_question(self, question, answers, selected_index = None, correct = None):
self._init_scene()
x = 50
y = 25
item = QGraphicsSimpleTextItem(question)
item.setBrush(self.TEXT_COLOR)
item.setFont(self.BOLDISH)
item.setX(x)
item.setY(y)
self.qtscene.addItem(item)
self.references.append(item)
y += 75
for index, answer in enumerate(answers):
index += 1
item = QGraphicsSimpleTextItem("%s) %s" % (index, answer))
item.setBrush(self.TEXT_COLOR)
item.setFont(self.NORMALISH)
item.setX(x)
item.setY(y)
item.setAcceptHoverEvents(True)
self.qtscene.addItem(item)
self.references.append(item)
#TODO: do not register click but do show check or not
if not selected_index:
item.hoverEnterEvent = partial(self.on_hover_answer, item)
item.hoverLeaveEvent = partial(self.on_unhover_answer, item)
item.mousePressEvent = partial(self.on_click_answer, index)
elif selected_index == index:
if correct:
item = QGraphicsSimpleTextItem(u"\u2713")
item.setBrush(QBrush(QColor(0,150,0)))
item.setX(0)
else:
item = QGraphicsSimpleTextItem("X")
item.setBrush(QBrush(QColor(255,0,0)))
item.setX(3)
item.setFont(self.BOLDISH)
item.setY(y)
self.qtscene.addItem(item)
self.references.append(item)
y += 50
return x, y
示例5: ActiveSliceHandle
# 需要导入模块: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setX [as 别名]
class ActiveSliceHandle(QGraphicsItem):
"""docstring for ActiveSliceHandle"""
_baseWidth = styles.PATH_BASE_WIDTH
_brush = QBrush(styles.orangefill)
_labelbrush = QBrush(styles.orangestroke)
_pen = QPen(styles.orangestroke, styles.SLICE_HANDLE_STROKE_WIDTH)
_myfont = QFont("Times", 12, QFont.Bold)
def __init__(self, pathHelixGroup):
super(ActiveSliceHandle, self).__init__(pathHelixGroup)
self._pathHelixGroup = None
self._activeSlice = 0
self._dragMode = False
self._label = QGraphicsSimpleTextItem("", parent=self)
self._label.setPos(0, -18)
self._label.setFont(self._myfont)
self._label.setBrush(self._labelbrush)
self._label.hide()
self.setPathHelixGroup(pathHelixGroup)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setAcceptHoverEvents(True)
self.setZValue(styles.ZACTIVESLICEHANDLE)
def controller(self):
return self._pathHelixGroup.controller()
def part(self):
return self._pathHelixGroup.part()
def pathHelixGroup(self):
return self._pathHelixGroup
def setPathHelixGroup(self, newPHG):
if self._pathHelixGroup:
self._pathHelixGroup.geometryChanged.disconnect(\
self.prepareGeometryChange)
self._pathHelixGroup.displayedVHsChanged.disconnect(self._hideIfEmptySelection)
if self._pathHelixGroup and self._pathHelixGroup.part():
self._pathHelixGroup.part().activeSliceWillChange.disconnect(\
self._updateActiveSlice)
self._pathHelixGroup = newPHG
newPHG.geometryChanged.connect(self.prepareGeometryChange)
newPHG.part().activeSliceWillChange.connect(self._updateActiveSlice)
newPHG.displayedVHsChanged.connect(self._hideIfEmptySelection)
self._hideIfEmptySelection()
self._updateActiveSlice(newPHG.part().activeSlice())
def activeSlice(self):
return self.part().activeSlice()
def setActiveSlice(self, baseIndex):
self.part().setActiveSlice(baseIndex)
def _hideIfEmptySelection(self):
self.setVisible(len(self.pathHelixGroup().displayedVHs())>0)
def _updateActiveSlice(self, baseIndex):
"""The slot that receives active slice changed notifications from
the part and changes the receiver to reflect the part"""
bi = int(baseIndex)
if bi < 0 or bi >= self.part().dimensions()[2]:
raise IndexError
self.setPos(bi * self._baseWidth, -styles.PATH_HELIX_PADDING)
self._activeSlice = bi
if self._label:
self._label.setText("%d" % bi)
self._label.setX((self._baseWidth -\
self._label.boundingRect().width()) / 2)
def boundingRect(self):
return QRectF(0, 0, self._baseWidth,\
self.pathHelixGroup().boundingRect().height())
def paint(self, painter, option, widget=None):
if self.boundingRect().height() > 0:
painter.setBrush(self._brush)
painter.setPen(self._pen)
painter.drawRect(self.boundingRect())
self._label.show()
else:
self._label.hide()
def resetBounds(self, maxBase):
"""Call after resizing virtualhelix canvas."""
self.maxBase = maxBase
self.maxX = (maxBase - 1) * self._baseWidth
def hoverEnterEvent(self, event):
if self.controller().isSelectToolActive():
self.setCursor(Qt.OpenHandCursor)
QGraphicsItem.hoverEnterEvent(self, event)
# end def
# def hoverMoveEvent(self, event):
# if not self.controller().isSelectToolActive():
# # pass None, but if needed pass self for having a special
# # behavior for the slice helix
# self.controller().toolHoverMove(None, event, flag=True)
# QGraphicsItem.hoverMoveEvent(self, event)
# end def
#.........这里部分代码省略.........