本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsTextItem.boundingRect方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.boundingRect方法的具体用法?Python QGraphicsTextItem.boundingRect怎么用?Python QGraphicsTextItem.boundingRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.boundingRect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphicsTextWidget
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
class GraphicsTextWidget(QGraphicsWidget):
def __init__(self, text, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.labelItem = QGraphicsTextItem(self)
self.setHtml(text)
self.labelItem.document().documentLayout().documentSizeChanged.connect(
self.onLayoutChanged
)
def setGeometry(self, rect):
self.prepareGeometryChange()
super().setGeometry(rect)
def onLayoutChanged(self, *args):
self.updateGeometry()
def sizeHint(self, which, constraint=QSizeF()):
if which == Qt.MinimumSize:
return self.labelItem.boundingRect().size()
else:
return self.labelItem.boundingRect().size()
def setTextWidth(self, width):
self.labelItem.setTextWidth(width)
def setHtml(self, text):
self.labelItem.setHtml(text)
示例2: __init__
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
def __init__(self, name, values, scale, name_offset, offset, get_points,
title, get_probabilities):
super().__init__()
self.scale = scale
self.offset = offset
self.get_points = get_points
self.min_val = min(values)
self.max_val = max(values)
# leading labels
font = name.document().defaultFont()
font.setWeight(QFont.Bold)
name_total = QGraphicsTextItem("Total", self)
name_total.setFont(font)
name_total.setPos(name_offset, -25)
name.setFont(font)
name.setPos(name_offset, 10)
name.setParentItem(self)
# prediction marker
self.dot = ProbabilitiesDotItem(
self.DOT_RADIUS, scale, offset, values[0], values[-1],
title, get_probabilities)
self.dot.setPos(0, (- self.DOT_RADIUS + self.y_diff) / 2)
self.dot.setParentItem(self)
# pylint: disable=unused-variable
# two lines
t_line = QGraphicsLineItem(self.min_val * scale + offset, 0,
self.max_val * scale + offset, 0,
self)
p_line = QGraphicsLineItem(self.min_val * scale + offset, self.y_diff,
self.max_val * scale + offset, self.y_diff,
self)
# ticks and labels
old_x_tick = values[0] * scale + offset
for i, value in enumerate(values[1:]):
x_tick = value * scale + offset
x = x_tick - (x_tick - old_x_tick) / 2
half_tick = QGraphicsLineItem(x, - self.tick_height / 2, x, 0,
self)
old_x_tick = x_tick
if i == len(values) - 2:
break
text = QGraphicsTextItem(str(abs(value) if value == -0 else value),
self)
x_text = value * scale - text.boundingRect().width() / 2 + offset
y_text = - text.boundingRect().height() - self.DOT_RADIUS * 0.7
text.setPos(x_text, y_text)
tick = QGraphicsLineItem(x_tick, -self.tick_height, x_tick, 0,
self)
self.prob_items = [
(i / 10, QGraphicsTextItem(" " + str(i * 10) + " "),
QGraphicsLineItem(0, 0, 0, 0)) for i in range(1, 10)]
示例3: LegendItemTitle
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
class LegendItemTitle(QGraphicsWidget):
"""Legend item title - the text displayed in the legend.
This should only really be used in conjunction with ˙LegendItem˙.
Parameters
----------
text : str
parent : QGraphicsItem
font : QFont
This
"""
_size_hint = QSizeF(100, 10)
def __init__(self, text, parent, font):
super().__init__(parent)
self.__text = QGraphicsTextItem(text.title())
self.__text.setParentItem(self)
self.__text.setFont(font)
self._size_hint = QSizeF(self.__text.boundingRect().size())
def sizeHint(self, size_hint, size_constraint=None, *args, **kwargs):
return self._size_hint
示例4: OWLegendTitle
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
class OWLegendTitle(QGraphicsObject):
"""
A legend item that shows ``text`` with a bold font and no symbol.
"""
def __init__(self, text, parent):
QGraphicsObject.__init__(self, parent)
self.text_item = QGraphicsTextItem(text + ':', self)
f = self.text_item.font()
f.setBold(True)
self.text_item.setFont(f)
self.rect_item = QGraphicsRectItem(self.text_item.boundingRect(), self)
self.rect_item.setPen(QPen(Qt.NoPen))
self.rect_item.stackBefore(self.text_item)
def boundingRect(self):
return self.text_item.boundingRect()
def paint(self, painter, option, widget):
pass
示例5: OWLegendItem
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [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
示例6: setPos
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
def setPos(self, x, y):
"""setPos with adjustment for alignment"""
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)
示例7: VennIntersectionArea
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [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()
示例8: LinkItem
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
class LinkItem(QGraphicsWidget):
"""
A Link item in the canvas that connects two :class:`.NodeItem`\s in the
canvas.
The link curve connects two `Anchor` items (see :func:`setSourceItem`
and :func:`setSinkItem`). Once the anchors are set the curve
automatically adjusts its end points whenever the anchors move.
An optional source/sink text item can be displayed above the curve's
central point (:func:`setSourceName`, :func:`setSinkName`)
"""
#: Z value of the item
Z_VALUE = 0
#: Runtime link state value
#: These are pulled from SchemeLink.State for ease of binding to it's
#: state
State = SchemeLink.State
#: The link has no associated state.
NoState = SchemeLink.NoState
#: Link is empty; the source node does not have any value on output
Empty = SchemeLink.Empty
#: Link is active; the source node has a valid value on output
Active = SchemeLink.Active
#: The link is pending; the sink node is scheduled for update
Pending = SchemeLink.Pending
def __init__(self, *args):
self.__boundingRect = None
super().__init__(*args)
self.setFlag(QGraphicsItem.ItemHasNoContents, True)
self.setAcceptedMouseButtons(Qt.RightButton | Qt.LeftButton)
self.setAcceptHoverEvents(True)
self.setZValue(self.Z_VALUE)
self.sourceItem = None
self.sourceAnchor = None
self.sinkItem = None
self.sinkAnchor = None
self.curveItem = LinkCurveItem(self)
self.sourceIndicator = LinkAnchorIndicator(self)
self.sinkIndicator = LinkAnchorIndicator(self)
self.sourceIndicator.hide()
self.sinkIndicator.hide()
self.linkTextItem = QGraphicsTextItem(self)
self.linkTextItem.setAcceptedMouseButtons(Qt.NoButton)
self.linkTextItem.setAcceptHoverEvents(False)
self.__sourceName = ""
self.__sinkName = ""
self.__dynamic = False
self.__dynamicEnabled = False
self.__state = LinkItem.NoState
self.hover = False
self.prepareGeometryChange()
self.__updatePen()
self.__boundingRect = None
self.__updatePalette()
self.__updateFont()
def setSourceItem(self, item, anchor=None):
"""
Set the source `item` (:class:`.NodeItem`). Use `anchor`
(:class:`.AnchorPoint`) as the curve start point (if ``None`` a new
output anchor will be created using ``item.newOutputAnchor()``).
Setting item to ``None`` and a valid anchor is a valid operation
(for instance while mouse dragging one end of the link).
"""
if item is not None and anchor is not None:
if anchor not in item.outputAnchors():
raise ValueError("Anchor must be belong to the item")
if self.sourceItem != item:
if self.sourceAnchor:
# Remove a previous source item and the corresponding anchor
self.sourceAnchor.scenePositionChanged.disconnect(
self._sourcePosChanged
)
if self.sourceItem is not None:
self.sourceItem.removeOutputAnchor(self.sourceAnchor)
self.sourceItem = self.sourceAnchor = None
self.sourceItem = item
if item is not None and anchor is None:
# Create a new output anchor for the item if none is provided.
anchor = item.newOutputAnchor()
#.........这里部分代码省略.........
示例9: OWAxis
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import boundingRect [as 别名]
#.........这里部分代码省略.........
self.line_item.setLine(self.graph_line)
self.line_item.setPen(line_color)
if self.title:
self.title_item.setHtml('<b>' + self.title + '</b>')
self.title_item.setDefaultTextColor(text_color)
if self.title_location == AxisMiddle:
title_p = 0.5
elif self.title_location == AxisEnd:
title_p = 0.95
else:
title_p = 0.05
title_pos = self.graph_line.pointAt(title_p)
v = self.graph_line.normalVector().unitVector()
dense_text = False
if hasattr(self, 'title_margin'):
offset = self.title_margin
elif self._ticks:
if self.should_be_expanded():
offset = 55
dense_text = True
else:
offset = 35
else:
offset = 10
if self.title_above:
title_pos += (v.p2() - v.p1()) * (offset + QFontMetrics(self.title_item.font()).height())
else:
title_pos -= (v.p2() - v.p1()) * offset
## TODO: Move it according to self.label_pos
self.title_item.setVisible(self.show_title)
self.title_item.setRotation(-self.graph_line.angle())
c = self.title_item.mapToParent(self.title_item.boundingRect().center())
tl = self.title_item.mapToParent(self.title_item.boundingRect().topLeft())
self.title_item.setPos(title_pos - c + tl)
## Arrows
if not zoom_only:
if self.start_arrow_item:
self.scene().removeItem(self.start_arrow_item)
self.start_arrow_item = None
if self.end_arrow_item:
self.scene().removeItem(self.end_arrow_item)
self.end_arrow_item = None
if self.arrows & AxisStart:
if not zoom_only or not self.start_arrow_item:
self.start_arrow_item = QGraphicsPathItem(self.arrow_path, self)
self.start_arrow_item.setPos(self.graph_line.p1())
self.start_arrow_item.setRotation(-self.graph_line.angle() + 180)
self.start_arrow_item.setBrush(line_color)
self.start_arrow_item.setPen(line_color)
if self.arrows & AxisEnd:
if not zoom_only or not self.end_arrow_item:
self.end_arrow_item = QGraphicsPathItem(self.arrow_path, self)
self.end_arrow_item.setPos(self.graph_line.p2())
self.end_arrow_item.setRotation(-self.graph_line.angle())
self.end_arrow_item.setBrush(line_color)
self.end_arrow_item.setPen(line_color)
## Labels
n = len(self._ticks)
resize_plot_item_list(self.label_items, n, QGraphicsTextItem, self)
resize_plot_item_list(self.label_bg_items, n, QGraphicsRectItem, self)