本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsTextItem.setFont方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsTextItem.setFont方法的具体用法?Python QGraphicsTextItem.setFont怎么用?Python QGraphicsTextItem.setFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsTextItem
的用法示例。
在下文中一共展示了QGraphicsTextItem.setFont方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LegendItemTitle
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setFont [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
示例2: __init__
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setFont [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: Marker
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setFont [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))
示例4: OWLegendTitle
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setFont [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: LinkItem
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsTextItem [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsTextItem import setFont [as 别名]
#.........这里部分代码省略.........
"""
# This getter/setter pair override a property from the base class.
# They should be renamed to e.g. setLinkEnabled/linkEnabled
self.curveItem.setLinkEnabled(enabled)
def isEnabled(self):
return self.curveItem.isLinkEnabled()
def setDynamicEnabled(self, enabled):
"""
Set the link's dynamic enabled state.
If the link is `dynamic` it will be rendered in red/green color
respectively depending on the state of the dynamic enabled state.
"""
if self.__dynamicEnabled != enabled:
self.__dynamicEnabled = enabled
if self.__dynamic:
self.__updatePen()
def isDynamicEnabled(self):
"""
Is the link dynamic enabled.
"""
return self.__dynamicEnabled
def setDynamic(self, dynamic):
"""
Mark the link as dynamic (i.e. it responds to
:func:`setDynamicEnabled`).
"""
if self.__dynamic != dynamic:
self.__dynamic = dynamic
self.__updatePen()
def isDynamic(self):
"""
Is the link dynamic.
"""
return self.__dynamic
def setRuntimeState(self, state):
"""
Style the link appropriate to the LinkItem.State
Parameters
----------
state : LinkItem.State
"""
if self.__state != state:
self.__state = state
if state & LinkItem.Pending:
self.sinkIndicator.setBrush(QBrush(Qt.red))
else:
self.sinkIndicator.setBrush(QBrush(QColor("#9CACB4")))
self.__updatePen()
def runtimeState(self):
return self.__state
def __updatePen(self):
self.prepareGeometryChange()
self.__boundingRect = None
if self.__dynamic:
if self.__dynamicEnabled:
color = QColor(0, 150, 0, 150)
else:
color = QColor(150, 0, 0, 150)
normal = QPen(QBrush(color), 2.0)
hover = QPen(QBrush(color.darker(120)), 2.1)
else:
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
hover = QPen(QBrush(QColor("#7D7D7D")), 2.1)
if self.__state & LinkItem.Empty:
pen_style = Qt.DashLine
else:
pen_style = Qt.SolidLine
normal.setStyle(pen_style)
hover.setStyle(pen_style)
if self.hover:
pen = hover
else:
pen = normal
self.curveItem.setPen(pen)
def __updatePalette(self):
self.linkTextItem.setDefaultTextColor(
self.palette().color(QPalette.Text))
def __updateFont(self):
self.linkTextItem.setFont(self.font())