本文整理汇总了Python中PyQt5.Qt.QPainter.font方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.font方法的具体用法?Python QPainter.font怎么用?Python QPainter.font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.font方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def paintEvent(self, event):
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax/2.)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray/2.)
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
spmap = self.pixmap.scaled(target.size() * dpr, Qt.KeepAspectRatio, Qt.SmoothTransformation)
spmap.setDevicePixelRatio(dpr)
p.drawPixmap(target, spmap)
if gprefs['bd_overlay_cover_size']:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例2: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def paintEvent(self, ev):
painter = QPainter(self)
painter.setRenderHint(QPainter.TextAntialiasing)
f = painter.font()
f.setBold(True)
f.setPixelSize(self.height() - 1)
painter.setFont(f)
painter.setPen(QColor('red' if self.is_enabled else 'green'))
painter.drawText(self.rect(), Qt.AlignCenter, 'Z')
painter.end()
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def paintEvent(self, ev):
br = ev.region().boundingRect()
QWidget.paintEvent(self, ev)
p = QPainter(self)
p.setClipRect(br)
f = p.font()
f.setBold(True)
f.setPointSize(20)
p.setFont(f)
p.setPen(Qt.SolidLine)
r = QRect(0, self.dummy.geometry().top() + 10, self.geometry().width(), 150)
p.drawText(r, Qt.AlignHCenter | Qt.AlignTop | Qt.TextSingleLine, self.text)
p.end()
示例4: create_icon
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def create_icon(text, palette=None, sz=32, divider=2):
if palette is None:
palette = QApplication.palette()
img = QImage(sz, sz, QImage.Format_ARGB32)
img.fill(Qt.transparent)
p = QPainter(img)
p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
qDrawShadeRect(p, img.rect(), palette, fill=QColor('#ffffff'), lineWidth=1, midLineWidth=1)
f = p.font()
f.setFamily('Liberation Sans'), f.setPixelSize(sz // divider), f.setBold(True)
p.setFont(f), p.setPen(Qt.black)
p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
p.end()
return QIcon(QPixmap.fromImage(img))
示例5: create_icon
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def create_icon(text, palette=None, sz=None, divider=2, fill='white'):
if isinstance(fill, basestring):
fill = QColor(fill)
sz = sz or int(math.ceil(tprefs['toolbar_icon_size'] * QApplication.instance().devicePixelRatio()))
if palette is None:
palette = QApplication.palette()
img = QImage(sz, sz, QImage.Format_ARGB32)
img.fill(Qt.transparent)
p = QPainter(img)
p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
if fill is not None:
qDrawShadeRect(p, img.rect(), palette, fill=fill, lineWidth=1, midLineWidth=1)
f = p.font()
f.setFamily('Liberation Sans'), f.setPixelSize(int(sz // divider)), f.setBold(True)
p.setFont(f), p.setPen(Qt.black)
p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
p.end()
return QIcon(QPixmap.fromImage(img))
示例6: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def paintEvent(self, event):
pmap = self.blank if self.pixmap is None or self.pixmap.isNull() else self.pixmap
target = self.rect()
scaled, width, height = fit_image(pmap.width(), pmap.height(), target.width(), target.height())
target.setRect(target.x(), target.y(), width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.pixmap is not None and not self.pixmap.isNull():
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例7: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import font [as 别名]
def paintEvent(self, event):
QWidget.paintEvent(self, event)
pmap = self._pixmap
if pmap.isNull():
return
w, h = pmap.width(), pmap.height()
ow, oh = w, h
cw, ch = self.rect().width(), self.rect().height()
scaled, nw, nh = fit_image(w, h, cw, ch)
if scaled:
pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.IgnoreAspectRatio,
Qt.SmoothTransformation)
w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio())
x = int(abs(cw - w)/2.)
y = int(abs(ch - h)/2.)
target = QRect(x, y, w, h)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.draw_border:
pen = QPen()
pen.setWidth(self.BORDER_WIDTH)
p.setPen(pen)
p.drawRect(target)
if self.show_size:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(ow, oh)
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()