当前位置: 首页>>代码示例>>Python>>正文


Python QtWidgets.QGraphicsTextItem类代码示例

本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsTextItem的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem类的具体用法?Python QGraphicsTextItem怎么用?Python QGraphicsTextItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QGraphicsTextItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, scene, text="", x=0, y=0,
                 alignment=Qt.AlignLeft | Qt.AlignTop, bold=False, font=None,
                 z=0, html_text=None, tooltip=None, show=True, 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 scene is not None:
            scene.addItem(self)
开发者ID:lanzagar,项目名称:orange3,代码行数:31,代码来源:__init__.py

示例2: LegendItemTitle

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
开发者ID:astaric,项目名称:orange3,代码行数:25,代码来源:owlegend.py

示例3: __init__

    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)]
开发者ID:astaric,项目名称:orange3,代码行数:56,代码来源:ownomogram.py

示例4: GraphicsTextWidget

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)
开发者ID:RachitKansal,项目名称:orange3,代码行数:28,代码来源:owimageviewer.py

示例5: __init__

    def __init__(self, parent, *args, **kwargs):
        QGraphicsTextItem.__init__(self, *args)
        GraphNode.__init__(self, **kwargs)
        self._background_brush = None
        self._rect = None

        self.parent = parent
        font = self.font()
        font.setPointSize(10)
        self.setFont(font)
        self.droplet = GraphicsDroplet(-5, 0, 10, 10, self)
        self.droplet.setPos(self.rect().center().x(), self.rect().height())
        self.document().contentsChanged.connect(self.update_contents)
        self.isOpen = True
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
开发者ID:janezd,项目名称:orange3,代码行数:15,代码来源:owtreeviewer2d.py

示例6: __init__

    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())
开发者ID:astaric,项目名称:orange3,代码行数:7,代码来源:owlegend.py

示例7: paint

 def paint(self, painter, option, widget=None):
     rect = self.rect()
     if self.isSelected():
         option.state ^= QStyle.State_Selected
     font = self.document().defaultFont()
     painter.setFont(font)
     if self.parent:
         draw_text = self.node_inst.description
         if self.parent.x() > self.x():  # node is to the left
             fm = QFontMetrics(font)
             x = rect.width() / 2 - fm.width(draw_text) - 4
         else:
             x = rect.width() / 2 + 4
         painter.drawText(QPointF(x, -self.line_descent - 1), draw_text)
     painter.save()
     painter.setBrush(self.backgroundBrush)
     painter.setPen(QPen(Qt.black, 3 if self.isSelected() else 0))
     adjrect = rect.adjusted(-3, 0, 0, 0)
     if not self.node_inst.children:
         painter.drawRoundedRect(adjrect, 4, 4)
     else:
         painter.drawRect(adjrect)
     painter.restore()
     painter.setClipRect(rect)
     return QGraphicsTextItem.paint(self, painter, option, widget)
开发者ID:RachitKansal,项目名称:orange3,代码行数:25,代码来源:owtreeviewer.py

示例8: __init__

    def __init__(self, *args):
        self.__boundingRect = None
        QGraphicsObject.__init__(self, *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.__sourceName = ""
        self.__sinkName = ""

        self.__dynamic = False
        self.__dynamicEnabled = False
        self.__state = LinkItem.Empty
        self.hover = False

        self.prepareGeometryChange()
        self.__updatePen()
        self.__boundingRect = None
开发者ID:rekonder,项目名称:orange3,代码行数:34,代码来源:linkitem.py

示例9: setPos

 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)
开发者ID:lanzagar,项目名称:orange3,代码行数:17,代码来源:__init__.py

示例10: __init__

    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
        )
开发者ID:RachitKansal,项目名称:orange3,代码行数:8,代码来源:owimageviewer.py

示例11: paint

    def paint(self, painter, option, widget=None):
        QGraphicsTextItem.paint(self, painter, option, widget)

        # Draw placeholder text if necessary
        if not (self.toPlainText() and self.toHtml()) and \
                self.__placeholderText and \
                not (self.hasFocus() and \
                     self.textInteractionFlags() & Qt.TextEditable):
            brect = self.boundingRect()
            painter.setFont(self.font())
            metrics = painter.fontMetrics()
            text = metrics.elidedText(self.__placeholderText, Qt.ElideRight,
                                      brect.width())
            color = self.defaultTextColor()
            color.setAlpha(min(color.alpha(), 150))
            painter.setPen(QPen(color))
            painter.drawText(brect, Qt.AlignTop | Qt.AlignLeft, text)
开发者ID:PrimozGodec,项目名称:orange3,代码行数:17,代码来源:annotationitem.py

示例12: paint

 def paint(self, painter, option, widget=0):
     painter.save()
     painter.setBrush(self.backgroundBrush)
     painter.setPen(QPen(Qt.gray))
     rect = self.rect()
     painter.drawRoundedRect(rect, 4, 4)
     painter.restore()
     painter.setClipRect(rect)
     return QGraphicsTextItem.paint(self, painter, option, widget)
开发者ID:janezd,项目名称:orange3,代码行数:9,代码来源:owtreeviewer2d.py

示例13: __init__

 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)
开发者ID:RachitKansal,项目名称:orange3,代码行数:9,代码来源:owlegend.py

示例14: OWLegendTitle

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
开发者ID:RachitKansal,项目名称:orange3,代码行数:19,代码来源:owlegend.py

示例15: __init__

    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()
开发者ID:ales-erjavec,项目名称:orange3,代码行数:11,代码来源:owvenndiagram.py


注:本文中的AnyQt.QtWidgets.QGraphicsTextItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。