本文整理汇总了Python中PyQt4.QtGui.QGraphicsTextItem.setPos方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setPos方法的具体用法?Python QGraphicsTextItem.setPos怎么用?Python QGraphicsTextItem.setPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setPos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_text_item
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def get_text_item(self):
text_item = QGraphicsTextItem(self.text.text, None)
text_item.setDefaultTextColor(self.text.style.colour) # QGraphicsTextItem
#text_item.setPen(self.text.style.colour) # QGraphicsSimpleTextItem
text_item.setFont(self.text.style.font)
text_item.setPos(0,0)
return text_item
示例2: showTextLabel
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
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
示例3: qt_test
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
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_())
示例4: annotate
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def annotate(self):
text, bool_ = QInputDialog.getText(self.view, "Annotation dialog", "Annotation:")
g=QGraphicsTextItem(str(text))
g.setFlag(QGraphicsItem.ItemIgnoresTransformations)
g.setFlag(QGraphicsItem.ItemIsMovable)
g.setTextInteractionFlags(Qt.TextEditorInteraction)
font=qApp.instance().font()
font.setPointSizeF(10.)
g.setFont(font)
g.setDefaultTextColor(Qt.blue)
g.setPos(500,1e4)
self.trashItems.append(g)
self.pw.addItem(g)
示例5: label
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def label(self):
if self._label:
return self._label
font = QFont("Times", 30, QFont.Bold)
label = QGraphicsTextItem("Part 1")
label.setVisible(False)
label.setFont(font)
label.setParentItem(self)
label.setPos(0, -40)
label.setTextInteractionFlags(Qt.TextEditorInteraction)
label.inputMethodEvent = None
self._label = label
return label
示例6: set_functions_list
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def set_functions_list(self, functionsList, prefix="", sufix=""):
self.funtionsList = functionsList
self.funtionsListItems = []
self.maxHeight = 0
tempHeight = 0
for element in functionsList:
tempElement = QGraphicsTextItem(self)
tempElement.setPlainText(prefix + element + sufix)
tempElement.setPos(0, tempHeight)
tempHeight += tempElement.document().size().height()
if self.maxWidth < tempElement.document().size().width():
self.maxWidth = tempElement.document().size().width()
self.funtionsListItems.append(tempElement)
self.maxHeight = tempHeight
示例7: appendOffsetItems
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def appendOffsetItems(self, linesToAppend):
count = 0
x = 0
y = 25 + (len(self.offsetItems) * (self.pageh + 2))
# print "Y append offset ", y
while count <= linesToAppend:
item = QGraphicsTextItem()
item.setDefaultTextColor(QColor(Qt.red))
item.setFont(self.font)
item.setPos(x, y)
self.offsetItems.append(item)
self.scene.addItem(item)
y += self.pageh + 2
count += 1
示例8: initOffsetItems
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def initOffsetItems(self):
count = 0
x = 0
y = 25
while count <= self.displayLines:
item = QGraphicsTextItem()
item.setDefaultTextColor(QColor(Qt.red))
item.setFont(self.font)
item.setPos(x, y)
self.offsetItems.append(item)
y += self.pageh + 2
count += 1
#Add Items in scene
for item in self.offsetItems:
self.scene.addItem(item)
示例9: setPos
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def setPos(self, x, y):
self.x, self.y = x, y
rect = QGraphicsTextItem.boundingRect(self)
if self.vertical:
h, w = rect.height(), rect.width()
rect.setWidth(h)
rect.setHeight(-w)
if int(self.alignment & Qt.AlignRight):
x -= rect.width()
elif int(self.alignment & Qt.AlignHCenter):
x -= rect.width() / 2.
if int(self.alignment & Qt.AlignBottom):
y -= rect.height()
elif int(self.alignment & Qt.AlignVCenter):
y -= rect.height() / 2.
QGraphicsTextItem.setPos(self, x, y)
示例10: Marker
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
class Marker(orangeqt.PlotItem):
"""
Displays a text marker on the plot.
:param text: The text to display. It can be HTML-formatted
:type tex: str
:param x: The x coordinate of the marker's position
:type x: float
:param y: The y coordinate of the marker's position
:type y: float
:param align: The text alignment
:type align:
:param bold: If ``True``, the text will be show bold.
:type bold: int
:param color: The text color
:type color: QColor
:param brushColor: The color of the brush user to paint the background
:type color: QColor
:param size: Font size
:type size: int
Markers have the QGraphicsItem.ItemIgnoresTransformations flag set by default,
so text remains the same size when zooming. There is no need to scale the manually.
"""
def __init__(self, text, x, y, align, bold=0, color=None, brushColor=None, size=None):
orangeqt.PlotItem.__init__(self)
self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
self._item = QGraphicsTextItem(text, parent=self)
self._data_point = QPointF(x, y)
f = self._item.font()
f.setBold(bold)
if size:
f.setPointSize(size)
self._item.setFont(f)
self._item.setPos(x, y)
def update_properties(self):
self._item.setPos(self.graph_transform().map(self._data_point))
示例11: OWLegendItem
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
class OWLegendItem(QGraphicsObject):
"""
Represents a legend item with a title and a point symbol.
:param name: The text to display
:type name: str
:param point: The point symbol
:type point: :obj:`.OWPoint`
:param parent: The parent item, passed to QGraphicsItem
:type parent: :obj:`QGraphicsItem`
.. seealso:: :meth:`.OWLegend.add_item`, :meth:`.OWLegend.add_curve`.
"""
def __init__(self, name, point, parent):
QGraphicsObject.__init__(self, parent)
self.text_item = QGraphicsTextItem(name, self)
if point:
s = point.size()
height = max(2*s, self.text_item.boundingRect().height())
else:
height = self.text_item.boundingRect().height()
p = 0.5 * height
self.text_item.setPos(height, 0)
self.point_item = point
if point:
self.point_item.setParentItem(self)
self.point_item.setPos(p, p)
self._rect = QRectF(0, 0, height + self.text_item.boundingRect().width(), height )
self.rect_item = QGraphicsRectItem(self._rect, self)
self.rect_item.setPen(QPen(Qt.NoPen))
self.rect_item.stackBefore(self.text_item)
if self.point_item:
self.rect_item.stackBefore(self.point_item)
def boundingRect(self):
return self._rect
def paint(self, painter, option, widget):
pass
示例12: ItemUsuario
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
class ItemUsuario(ItemMovel):
def __init__(self, usuario, rect=QRectF(0, 0, 100, 50), parent=None):
super().__init__(False, True, rect, parent)
self._numConversasNaoVisualizadas = 0
self.selected = False
self._textItem = QGraphicsTextItem(self)
self._textItem.setFont(self.fontUser())
self._textItem.setPos(0, 10)
self.setaImg = ResourceUtil.getImage('images/right.png').scaled(80, 40, aspectRatioMode=Qt.KeepAspectRatio)
self.topoImg = ResourceUtil.getImage('images/fundo/topo.png')
self.background = ResourceUtil.getImage('images/postit3.png')
self.setUsuario(usuario)
def setUsuario(self, usuario):
self._usuario = usuario
self.atualizaTexto()
def getUsuario(self):
return self._usuario
def setNumConversasNaoVisualizadas(self, num):
self._numConversasNaoVisualizadas = num
self.atualizaTexto()
def atualizaTexto(self):
texto = "<center>{0} - {1}".format(self._usuario.getNome(), self._usuario.getIP())
if self._numConversasNaoVisualizadas > 0:
texto += " <b>({0})</b>".format(self._numConversasNaoVisualizadas)
texto += "</center>"
self._textItem.setHtml(texto)
def setRect(self, rect):
super().setRect(rect)
self._textItem.setTextWidth(rect.size().width() - self.setaImg.rect().width())
def paint(self, painter, widget, option):
painter.setPen(Qt.NoPen)
if self.selected:
rect = self.boundingRect()
rectImg = self.setaImg.rect()
painter.drawImage(rectImg.adjusted(rect.width() - rectImg.width(), 0, rect.width() - rectImg.width(), 0), self.setaImg)
painter.drawImage(self.boundingRect(), self.background)
"""if self.isUnderMouse():
painter.drawImage(self.boundingRect().adjusted(0,10,0,0), self.topoImg)
painter.save()
painter.setPen(Qt.NoPen)
st = Status.getInstance(self.getUsuario().getStatus())
if st == Status.ONLINE:
painter.setBrush(QColor(0,255,0,50))
elif st == Status.OCUPADO:
painter.setBrush(QColor(255,0,0,50))
elif st == Status.AUSENTE:
painter.setBrush(QColor(240, 226, 31, 50))
painter.drawRoundedRect(self.getRect(), 7, 5)
painter.restore()"""
super().paint(painter, widget, option)
def fontUser(self):
font = QFont("LoveYaLikeASister")
font.setBold(True)
return font
示例13: drawHistogram
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
def drawHistogram(self):
if self.result is None:
return
# Label the histogram
#self.minValueLabel.setText(str(self.minValue))
#self.maxValueLabel.setText(str(self.maxValue))
minvaltext = QGraphicsTextItem(str(self.minValue))
minvaltextheight = minvaltext.boundingRect().height()
maxvaltext = QGraphicsTextItem(str(self.maxValue))
maxvaltextwidth = maxvaltext.boundingRect().width()
#self.showInfo(str(self.result))
# Check which element should be used for the histogram
element = 1
maxvalue = 0.0
for i in range(len(self.result)):
if self.result[i][element] > maxvalue:
maxvalue = self.result[i][element]
# Find the maximum value for scaling
cutoffvalue = maxvalue
if (self.frequencyRangeSpinBox.value() > 0):
cutoffvalue = self.frequencyRangeSpinBox.value()
#self.maxNumberLabel.setText(str(maxvalue))
#self.maxNumberLabel.setText(str(cutoffvalue))
self.scene.clear()
if maxvalue == 0:
return
viewprect = QRectF(self.histogramGraphicsView.viewport().rect())
self.histogramGraphicsView.setSceneRect(viewprect)
bottom = self.histogramGraphicsView.sceneRect().bottom()
top = self.histogramGraphicsView.sceneRect().top()
left = self.histogramGraphicsView.sceneRect().left()
right = self.histogramGraphicsView.sceneRect().right()
height = bottom - top - 1
width = right - left - 1
padding = 3
toppadding = 3
bottompadding = minvaltextheight
# Determine the width of the left margin (depends on the y range)
clog = log(cutoffvalue,10)
clogint = int(clog)
#clogrem = clog % clogint
yincr = pow(10,clogint)
dummytext = QGraphicsTextItem(str(yincr))
# The left padding must accomodate the y labels
leftpadding = dummytext.boundingRect().width()
#leftpadding = 30
# Find the width of the maximium frequency label
maxfreqtext = QGraphicsTextItem(str(cutoffvalue))
maxfreqtextwidth = maxvaltext.boundingRect().width()
rightpadding = maxfreqtextwidth
width = width - (leftpadding + rightpadding)
height = height - (toppadding + bottompadding)
barwidth = width / self.bins
#center = QPoint(left + width / 2.0, top + height / 2.0)
#start = QPointF(self.histogramGraphicsView.mapToScene(center))
# Create the histogram
for i in range(self.bins):
#barheight = height * self.result[i][element] / maxvalue
barheight = height * self.result[i][element] / cutoffvalue
barrect = QGraphicsRectItem(QRectF(leftpadding + barwidth * i,
height-barheight+toppadding, barwidth, barheight))
barbrush = QBrush(QColor(255,153,102))
barrect.setBrush(barbrush)
self.scene.addItem(barrect)
# Determine the increments for the horizontal lines
if (cutoffvalue // yincr <= 5 and yincr > 1 ):
yincr = yincr / 2
if (cutoffvalue // yincr < 5 and yincr > 10 ):
yincr = yincr / 2
# Draw horizontal lines with labels
yval = 0
while (yval <= cutoffvalue):
scval = height + toppadding - yval * height / cutoffvalue
hline = QGraphicsLineItem(QLineF(leftpadding-2, scval,width+(leftpadding),scval))
hlinepen = QPen(QColor(153,153,153))
hline.setPen(hlinepen)
self.scene.addItem(hline)
ylabtext = QGraphicsTextItem(str(int(yval)))
ylabtextheight = ylabtext.boundingRect().height()
ylabtextwidth = ylabtext.boundingRect().width()
ylabtext.setPos(leftpadding - ylabtextwidth, scval - ylabtextheight/2)
if (scval - ylabtextheight/2 > 0):
self.scene.addItem(ylabtext)
yval = yval + yincr
#yincr = (cutoffvalue / 10)
minvaltextwidth = minvaltext.boundingRect().width()
minvaltext.setPos(leftpadding - minvaltextwidth/2, height + toppadding + bottompadding - minvaltextheight)
self.scene.addItem(minvaltext)
maxvaltext.setPos(leftpadding + width - maxvaltextwidth/2, height + toppadding + bottompadding - minvaltextheight)
self.scene.addItem(maxvaltext)
maxfreqtext.setPos(leftpadding + width, 0)
self.scene.addItem(maxfreqtext)
示例14: VennIntersectionArea
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
class VennIntersectionArea(QGraphicsPathItem):
def __init__(self, parent=None, text=""):
super(QGraphicsPathItem, self).__init__(parent)
self.setAcceptHoverEvents(True)
self.setPen(QPen(Qt.NoPen))
self.text = QGraphicsTextItem(self)
layout = self.text.document().documentLayout()
layout.documentSizeChanged.connect(self._onLayoutChanged)
self._text = ""
self._anchor = QPointF()
def setText(self, text):
if self._text != text:
self._text = text
self.text.setPlainText(text)
def text(self):
return self._text
def setTextAnchor(self, pos):
if self._anchor != pos:
self._anchor = pos
self._updateTextAnchor()
def hoverEnterEvent(self, event):
self.setZValue(self.zValue() + 1)
return QGraphicsPathItem.hoverEnterEvent(self, event)
def hoverLeaveEvent(self, event):
self.setZValue(self.zValue() - 1)
return QGraphicsPathItem.hoverLeaveEvent(self, event)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if event.modifiers() & Qt.AltModifier:
self.setSelected(False)
elif event.modifiers() & Qt.ControlModifier:
self.setSelected(not self.isSelected())
elif event.modifiers() & Qt.ShiftModifier:
self.setSelected(True)
else:
for area in self.parentWidget().vennareas():
area.setSelected(False)
self.setSelected(True)
def mouseReleaseEvent(self, event):
pass
def paint(self, painter, option, widget=None):
painter.save()
path = self.path()
brush = QBrush(self.brush())
pen = QPen(self.pen())
if option.state & QStyle.State_Selected:
pen.setColor(Qt.red)
brush.setStyle(Qt.DiagCrossPattern)
brush.setColor(QColor(40, 40, 40, 100))
elif option.state & QStyle.State_MouseOver:
pen.setColor(Qt.blue)
if option.state & QStyle.State_MouseOver:
brush.setColor(QColor(100, 100, 100, 100))
if brush.style() == Qt.NoBrush:
# Make sure the highlight is actually visible.
brush.setStyle(Qt.SolidPattern)
painter.setPen(pen)
painter.setBrush(brush)
painter.drawPath(path)
painter.restore()
def itemChange(self, change, value):
if change == QGraphicsPathItem.ItemSelectedHasChanged:
self.setZValue(self.zValue() + (1 if value else -1))
return QGraphicsPathItem.itemChange(self, change, value)
def _updateTextAnchor(self):
rect = self.text.boundingRect()
pos = anchor_rect(rect, self._anchor)
self.text.setPos(pos)
def _onLayoutChanged(self):
self._updateTextAnchor()
示例15: NodeItem
# 需要导入模块: from PyQt4.QtGui import QGraphicsTextItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsTextItem import setPos [as 别名]
#.........这里部分代码省略.........
def setupGraphics(self):
"""
Set up the graphics.
"""
shape_rect = QRectF(-24, -24, 48, 48)
self.shapeItem = NodeBodyItem(self)
self.shapeItem.setShapeRect(shape_rect)
self.shapeItem.setAnimationEnabled(self.__animationEnabled)
# Rect for widget's 'ears'.
anchor_rect = QRectF(-31, -31, 62, 62)
self.inputAnchorItem = SinkAnchorItem(self)
input_path = QPainterPath()
start_angle = 180 - self.ANCHOR_SPAN_ANGLE / 2
input_path.arcMoveTo(anchor_rect, start_angle)
input_path.arcTo(anchor_rect, start_angle, self.ANCHOR_SPAN_ANGLE)
self.inputAnchorItem.setAnchorPath(input_path)
self.outputAnchorItem = SourceAnchorItem(self)
output_path = QPainterPath()
start_angle = self.ANCHOR_SPAN_ANGLE / 2
output_path.arcMoveTo(anchor_rect, start_angle)
output_path.arcTo(anchor_rect, start_angle, - self.ANCHOR_SPAN_ANGLE)
self.outputAnchorItem.setAnchorPath(output_path)
self.inputAnchorItem.hide()
self.outputAnchorItem.hide()
# Title caption item
self.captionTextItem = QGraphicsTextItem(self)
self.captionTextItem.setPlainText("")
self.captionTextItem.setPos(0, 33)
def iconItem(standard_pixmap):
item = GraphicsIconItem(self, icon=standard_icon(standard_pixmap),
iconSize=QSize(16, 16))
item.hide()
return item
self.errorItem = iconItem(QStyle.SP_MessageBoxCritical)
self.warningItem = iconItem(QStyle.SP_MessageBoxWarning)
self.infoItem = iconItem(QStyle.SP_MessageBoxInformation)
# TODO: Remove the set[Widget|Category]Description. The user should
# handle setting of icons, title, ...
def setWidgetDescription(self, desc):
"""
Set widget description.
"""
self.widget_description = desc
if desc is None:
return
icon = icon_loader.from_description(desc).get(desc.icon)
if icon:
self.setIcon(icon)
if not self.title():
self.setTitle(desc.name)
if desc.inputs:
self.inputAnchorItem.show()
if desc.outputs:
self.outputAnchorItem.show()