當前位置: 首頁>>代碼示例>>Python>>正文


Python QFontMetrics.width方法代碼示例

本文整理匯總了Python中AnyQt.QtGui.QFontMetrics.width方法的典型用法代碼示例。如果您正苦於以下問題:Python QFontMetrics.width方法的具體用法?Python QFontMetrics.width怎麽用?Python QFontMetrics.width使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AnyQt.QtGui.QFontMetrics的用法示例。


在下文中一共展示了QFontMetrics.width方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: paint

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
 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,代碼行數:27,代碼來源:owtreeviewer.py

示例2: __naturalsh

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
 def __naturalsh(self):
     fm = QFontMetrics(self.font())
     spacing = self.__spacing
     N = len(self.__items)
     width = max((fm.width(text) for text in self.__items),
                 default=0)
     height = N * fm.height() + (N - 1) * spacing
     return QSizeF(width, height)
開發者ID:PrimozGodec,項目名稱:orange3,代碼行數:10,代碼來源:owsilhouetteplot.py

示例3: update_contents

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
 def update_contents(self):
     self.prepareGeometryChange()
     self.setTextWidth(-1)
     self.setTextWidth(self.document().idealWidth())
     self.droplet.setPos(self.rect().center().x(), self.rect().height())
     self.droplet.setVisible(bool(self.branches))
     fm = QFontMetrics(self.document().defaultFont())
     attr = self.node_inst.attr
     self.attr_text_w = fm.width(attr.name if attr else "")
     self.attr_text_h = fm.lineSpacing()
     self.line_descent = fm.descent()
     if self.pie is not None:
         self.pie.setPos(self.rect().right(), self.rect().center().y())
開發者ID:RachitKansal,項目名稱:orange3,代碼行數:15,代碼來源:owtreeviewer.py

示例4: _update_points_labels

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
    def _update_points_labels(self):
        if self.plotdata.points is None:
            return
        for point_label in self.plotdata.point_labels:
            self.graph.plot_widget.removeItem(point_label)
        self.plotdata.point_labels = []
        sx, sy = self.graph.view_box.viewPixelSize()

        for row in self.plotdata.points:
            ti = TextItem()
            metrics = QFontMetrics(ti.textItem.font())
            text_width = ((RANGE.width())/2. - np.abs(row[0])) / sx
            name = row[2].name
            ti.setText(name)
            ti.setTextWidth(text_width)
            ti.setColor(QColor(0, 0, 0))
            br = ti.boundingRect()
            width = metrics.width(name) if metrics.width(name) < br.width() else br.width()
            width = sx * (width + 5)
            height = sy * br.height()
            ti.setPos(row[0] - (row[0] < 0) * width, row[1] + (row[1] > 0) * height)
            self.plotdata.point_labels.append(ti)
            self.graph.plot_widget.addItem(ti)
開發者ID:astaric,項目名稱:orange3,代碼行數:25,代碼來源:owradviz.py

示例5: __init__

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
    def __init__(self, model, node_inst, parent=None):
        super().__init__(parent)
        self.model = model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = node_inst.attr
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if model.domain.class_var.is_discrete:
            self.pie = PieChart(node_inst.value, 8, self)
        else:
            self.pie = None
開發者ID:RachitKansal,項目名稱:orange3,代碼行數:18,代碼來源:owtreeviewer.py

示例6: __init__

# 需要導入模塊: from AnyQt.QtGui import QFontMetrics [as 別名]
# 或者: from AnyQt.QtGui.QFontMetrics import width [as 別名]
    def __init__(self, tree_adapter, node_inst, parent=None):
        super().__init__(parent)
        self.tree_adapter = tree_adapter
        self.model = self.tree_adapter.model
        self.node_inst = node_inst

        fm = QFontMetrics(self.document().defaultFont())
        attr = self.tree_adapter.attribute(node_inst)
        self.attr_text_w = fm.width(attr.name if attr else "")
        self.attr_text_h = fm.lineSpacing()
        self.line_descent = fm.descent()
        self._rect = None

        if self.model.domain.class_var.is_discrete:
            self.pie = PieChart(self.tree_adapter.get_distribution(node_inst)[0], 8, self)
        else:
            self.pie = None
開發者ID:astaric,項目名稱:orange3,代碼行數:19,代碼來源:owtreeviewer.py


注:本文中的AnyQt.QtGui.QFontMetrics.width方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。