本文整理汇总了Python中PyQt4.QtGui.QGraphicsTextItem类的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem类的具体用法?Python QGraphicsTextItem怎么用?Python QGraphicsTextItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGraphicsTextItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keyPressEvent
def keyPressEvent (self, event):
'''Re-implementation of the QGraphicsTextItem's method keyPressEvent in order to provide QGraphicsTextItem with the QLineEdit's textChanged Event.
@param event event
'''
self.emit (SIGNAL ('textChanged(QString)'), QString(self.toPlainText()))
QGraphicsTextItem.keyPressEvent(self, event)
示例2: PendulumGraphics
class PendulumGraphics(Pendulum):
"""pendulum which renders itself in a QGraphicsView"""
def initGraphics(self, gView):
self.gView = gView
self.gScene = QGraphicsScene(self.gView)
self.gView.setScene(self.gScene)
self.gText = QGraphicsTextItem("Pendulum")
self.gText.moveBy(0, -120)
self.gGrid = Graphics.Items.Grid(size=(-140, -140, 140, 140), xstep=20, ystep=20,
toolTip='the main grid')
self.gCross = Graphics.Items.CrossX(toolTip='this is the fix point of the pendulum')
self.gAxes = Graphics.Items.Axes(toolTip='theese are x,y-axes')
self.gPendulum = GPendulum()
self.gPendulum.setProperties((self.mass, self.length, self.radius, self.gravity,
self.omega, self.friction))
self.gScene.addItem(self.gGrid)
self.gScene.addItem(self.gText)
self.gScene.addItem(self.gCross)
self.gScene.addItem(self.gAxes)
self.gScene.addItem(self.gPendulum)
self.gView.setSceneRect(QRectF(-140, -140, 280, 280))
self.gPendulum.rotate(self.phi.v)
def reset(self):
self.gPendulum.rotate(self.initValues['phi']-self.phi.v)
Pendulum.reset(self)
def update(self, timeStep):
Pendulum.update(self, timeStep)
self.gPendulum.rotate(self.phiStep)
示例3: __init__
def __init__(self, canvas, text="", x=0, y=0,
alignment=Qt.AlignLeft | Qt.AlignTop, bold=0, font=None, z=0,
html_text=None, tooltip=None, show=1, vertical=False):
QGraphicsTextItem.__init__(self, text, None)
if font:
self.setFont(font)
if bold:
font = self.font()
font.setBold(bold)
self.setFont(font)
if html_text:
self.setHtml(html_text)
self.alignment = alignment
self.vertical = vertical
if vertical:
self.setRotation(-90)
self.setPos(x, y)
self.x, self.y = x, y
self.setZValue(z)
if tooltip:
self.setToolTip(tooltip)
if show:
self.show()
else:
self.hide()
if canvas is not None:
canvas.addItem(self)
示例4: focusInEvent
def focusInEvent (self, event):
'''Re-implementation of the QGraphicsTextItem's method focusOInEvent in order to change the text colour to red.
@param event event
'''
self.setDefaultTextColor (Qt.red)
QGraphicsTextItem.focusOutEvent(self, event)
示例5: __init__
def __init__(self, whex):
QGraphicsTextItem.__init__(self)
self.initValues(whex)
self.initPosition()
# self.initDocument()
self.initFont()
self.initMetricsValues()
示例6: initHeads
def initHeads(self):
self.offHead = QGraphicsTextItem()
self.hexHead = QGraphicsTextItem()
self.asciiHead = QGraphicsTextItem()
#Set Color
self.offHead.setDefaultTextColor(QColor(Qt.red))
self.hexHead.setDefaultTextColor(QColor(Qt.black))
self.asciiHead.setDefaultTextColor(QColor(Qt.darkCyan))
#Create Font
self.font = QFont("Gothic")
self.font.setFixedPitch(1)
self.font.setBold(False)
self.font.setPixelSize(14)
#Set Font
self.offHead.setFont(self.font)
self.hexHead.setFont(self.font)
self.asciiHead.setFont(self.font)
#Set Text
self.offHead.setPlainText("Offset")
self.hexHead.setPlainText("0 1 2 3 4 5 6 7 8 9 A B C D E F")
self.asciiHead.setPlainText("Ascii")
#Position
self.offHead.setPos(20, 0)
self.hexHead.setPos(95, 0)
self.asciiHead.setPos(520, 0)
#Add to scene
self.scene.addItem(self.offHead)
self.scene.addItem(self.hexHead)
self.scene.addItem(self.asciiHead)
headLine = QGraphicsLineItem(QLineF(0, 20, 615, 20))
self.scene.addItem(headLine)
示例7: focusOutEvent
def focusOutEvent (self, event):
'''Re-implementation of the QGraphicsTextItem's method focusOutEvent in order to provide QGraphicsTextItem with the QLineEdit's textChanged Event.
@param event event
'''
self.emit (SIGNAL ('textChanged(QString)'), QString(self.toPlainText()))
self.setDefaultTextColor (QColor (Qt.white).light (255))
QGraphicsTextItem.focusOutEvent(self, event)
示例8: __init__
def __init__(self, str0='', parent=None, scene=None):
QGraphicsTextItem.__init__ (self, str0, parent, scene)
self.setAcceptHoverEvents (False)
self.setAcceptedMouseButtons (Qt.NoButton)
self.setAcceptDrops (False)
self.setAcceptTouchEvents (False)
示例9: keyPressEvent
def keyPressEvent(self, keyEvent):
if keyEvent.key() == Qt.Key_Return or keyEvent.key() == Qt.Key_Enter:
if self.__isSingleLine:
self.setTextInteractionFlags(Qt.NoTextInteraction)
return
QGraphicsTextItem.keyPressEvent(self, keyEvent)
示例10: keyPressEvent
def keyPressEvent(self, event):
""" Stuff to do during key press events.
For now we have to adjust the outline box.
"""
QGraphicsTextItem.keyPressEvent(self, event)
self.adjust_size()
示例11: paint
def paint( self, painter, option, widget ):
""" Draws the edge text """
# Hide the dotted outline
itemOption = QStyleOptionGraphicsItem( option )
if itemOption.state & QStyle.State_Selected != 0:
itemOption.state = itemOption.state & ~QStyle.State_Selected
QGraphicsTextItem.paint( self, painter, itemOption, widget )
return
示例12: showTextLabel
def showTextLabel(self, x, y, secure=25):
"""
add labels of principle peaks of spectrum or chroma
on the plot, return the labels, that we can show hide
"""
maxis=[]#will contain tuple(rt, intens)
indexes=[]
#from core.MetObjects import MSAbstractTypes
from scipy.ndimage import gaussian_filter1d as gauss
z=gauss(y, 1)
#z = MSAbstractTypes.computeBaseLine(z, 92., 0.8)
i=0
while i <len(z)-1:
while z[i+1] >= z[i] and i < len(y)-2:
i+=1
maxis.append((x[i], y[i]))
indexes.append(i)
while z[i+1] <= z[i] and i<len(z)-2:
i+=1
i+=1
labels=[]
for t in sorted(maxis, key=lambda x:x[1])[-5:]:
g=QGraphicsTextItem(str(t[0]))
g.setFlag(QGraphicsItem.ItemIgnoresTransformations)
font=QApplication.font()
font.setPointSizeF(6.5)
g.setFont(font)
g.setDefaultTextColor(Qt.black)
g.setPos(t[0], t[1])
labels.append(g)
self.pw.addItem(g)
return labels
示例13: qt_test
def qt_test():
"""
Test that Qt actually works
"""
scene = QGraphicsScene()
text = QGraphicsTextItem(None, scene)
text.setHtml("<h2 align=\"center\">hello</h2><h2 align=\"center\">world 12334345354444444444444444444444444</h2>123");
text.setPos(QPointF(25,25))
view = QGraphicsView(scene)
view.show()
sys.exit(app.exec_())
示例14: label
def label(self):
if self._label:
return self._label
label = QGraphicsTextItem("")
label.setVisible(False)
label.setFont(self._font)
label.setParentItem(self)
label.setTextInteractionFlags(Qt.TextEditorInteraction)
label.inputMethodEvent = self.inputProcess
self._label = label
self._label.hide()
return label
示例15: paint
def paint(self, painter, option, widget=None):
painter.setPen(self.pen())
painter.setBrush( EDraw.EColor.DefaultFillColor )
style = QStyleOptionGraphicsItem()
style.state = ( QStyle.State_None )
painter.drawPolygon( EDraw.DefaultPolygon( self.boundingRect().width(), self.boundingRect().height() ) )
painter.translate( self.boundingRect().height() / 2 , 0.0)
QGraphicsTextItem.paint(self, painter, style, widget)