本文整理汇总了Python中PyQt5.Qt.QPainter.drawStaticText方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.drawStaticText方法的具体用法?Python QPainter.drawStaticText怎么用?Python QPainter.drawStaticText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.drawStaticText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawStaticText [as 别名]
def paintEvent(self, ev):
painter = QPainter(self)
painter.setClipRect(ev.rect())
pal = self.palette()
painter.fillRect(self.rect(), pal.color(pal.Base))
painter.setFont(self.parent().font())
painter.setPen(QPen(pal.color(pal.Text)))
width = self.rect().width()
for i, st, y, height in self.iter_visible_items():
painter.save()
if i == self.current_index:
painter.fillRect(0, y, width, height, pal.color(pal.Highlight))
painter.setPen(QPen(pal.color(pal.HighlightedText)))
painter.drawStaticText(0, y, st)
painter.restore()
painter.end()
if self.current_size_hint is None:
QTimer.singleShot(0, self.layout)
示例2: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawStaticText [as 别名]
def paintEvent(self, ev):
if not self.static_text or not self.static_text.text():
return
p = QPainter(self)
p.setRenderHint(p.TextAntialiasing)
# If text is too long too fit, fade it out at the end
self.static_text.setTextWidth(self.rect().width())
sz = self.static_text.size()
r = self.rect()
p.drawStaticText(0, (r.height() - sz.height()) // 2, self.static_text)
if sz.width() > r.width():
g = QLinearGradient(self.rect().topLeft(), self.rect().topRight())
c = QColor(self.sb_background)
c.setAlpha(0)
g.setColorAt(0, c)
g.setColorAt(0.8, c)
g.setColorAt(1.0, self.sb_background)
p.fillRect(self.rect(), QBrush(g))
p.end()
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawStaticText [as 别名]
def paintEvent(self, ev):
painter = QPainter(self)
painter.setClipRect(ev.rect())
pal = self.palette()
painter.fillRect(self.rect(), pal.color(pal.Text))
crect = self.rect().adjusted(1, 1, -1, -1)
painter.fillRect(crect, pal.color(pal.Base))
painter.setClipRect(crect)
painter.setFont(self.parent().font())
width = self.rect().width()
for i, st, y, height in self.iter_visible_items():
painter.save()
if i == self.current_index:
painter.fillRect(1, y, width, height, pal.color(pal.Highlight))
color = pal.color(QPalette.HighlightedText).name()
st = QStaticText(st)
text = st.text().partition('>')[2]
st.setText('<span style="color: %s">%s' % (color, text))
painter.drawStaticText(self.SIDE_MARGIN, y, st)
painter.restore()
painter.end()
if self.current_size_hint is None:
QTimer.singleShot(0, self.layout)