本文整理汇总了Python中PyQt5.Qt.QPainter.drawPixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.drawPixmap方法的具体用法?Python QPainter.drawPixmap怎么用?Python QPainter.drawPixmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPainter
的用法示例。
在下文中一共展示了QPainter.drawPixmap方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [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 drawPixmap [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:
draw_size(p, target, ow, oh)
p.end()
示例3: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, ev):
shown = self.button.isChecked()
ls = self.fm.lineSpacing()
painter = QPainter(self)
if self.mouse_over:
tool = QStyleOption()
tool.rect = self.rect()
tool.state = QStyle.State_Raised | QStyle.State_Active | QStyle.State_MouseOver
s = self.style()
s.drawPrimitive(QStyle.PE_PanelButtonTool, tool, painter, self)
painter.drawText(
0, 0,
self.width(),
ls, Qt.AlignCenter | Qt.TextSingleLine, self.text)
text = _('Hide') if shown else _('Show')
f = self.font()
f.setBold(True)
painter.setFont(f)
painter.drawText(
0, self.height() - ls,
self.width(),
ls, Qt.AlignCenter | Qt.TextSingleLine, text)
x = (self.width() - ICON_SZ) // 2
y = ls + (self.height() - ICON_SZ - 2 * ls) // 2
pmap = self.bright_icon if shown else self.dull_icon
painter.drawPixmap(x, y, pmap)
painter.end()
示例4: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, event):
w = self.viewport().rect().width()
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
floor = event.rect().bottom()
ceiling = event.rect().top()
fv = self.firstVisibleBlock().blockNumber()
origin = self.contentOffset()
doc = self.document()
lines = []
for num, text in self.headers:
top, bot = num, num + 3
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
painter.setFont(self.heading_font)
br = painter.drawText(3, y_top, w, y_bot - y_top - 5, Qt.TextSingleLine, text)
painter.setPen(QPen(self.palette().text(), 2))
painter.drawLine(0, br.bottom()+3, w, br.bottom()+3)
for top, bot, kind in self.changes:
if bot < fv:
continue
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top)).translated(origin).y()
y_bot = self.blockBoundingGeometry(doc.findBlockByNumber(bot)).translated(origin).y()
if max(y_top, y_bot) < ceiling:
continue
if min(y_top, y_bot) > floor:
break
if y_top != y_bot:
painter.fillRect(0, y_top, w, y_bot - y_top, self.diff_backgrounds[kind])
lines.append((y_top, y_bot, kind))
if top in self.images:
img, maxw = self.images[top][:2]
if bot > top + 1 and not img.isNull():
y_top = self.blockBoundingGeometry(doc.findBlockByNumber(top+1)).translated(origin).y() + 3
y_bot -= 3
scaled, imgw, imgh = fit_image(img.width(), img.height(), w - 3, y_bot - y_top)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.drawPixmap(QRect(3, y_top, imgw, imgh), img)
painter.end()
PlainTextEdit.paintEvent(self, event)
painter = QPainter(self.viewport())
painter.setClipRect(event.rect())
for top, bottom, kind in sorted(lines, key=lambda (t, b, k):{'replace':0}.get(k, 1)):
painter.setPen(QPen(self.diff_foregrounds[kind], 1))
painter.drawLine(0, top, w, top)
painter.drawLine(0, bottom - 1, w, bottom - 1)
示例5: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, ev):
if self.timer.isActive():
if not self.errored_out:
try:
draw_snake_spinner(QPainter(self), self.rect(), self.angle, self.light, self.dark)
except Exception:
import traceback
traceback.print_exc()
self.errored_out = True
else:
r = self.rect()
painter = QPainter(self)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
icon = downloads_icon()
pmap = icon.pixmap(r.width(), r.height())
x = (r.width() - int(pmap.width() / pmap.devicePixelRatio())) // 2
y = (r.height() - int(pmap.height() / pmap.devicePixelRatio())) // 2 + 1
painter.drawPixmap(x, y, pmap)
示例6: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, event):
if self.pixmap.isNull():
return
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax / 2.0)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray / 2.0)
target = QRect(x, y, min(canvas_size.width(), width), min(canvas_size.height(), height))
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, self.pixmap.scaled(target.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
p.end()
示例7: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [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()
示例8: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, ev):
if self.before_image is None:
return
canvas_size = self.rect()
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(canvas_size, self.before_image, self.before_image.rect())
if self.after_image is not None:
width = self._current_width
iw = self.after_image.width()
sh = min(self.after_image.height(), canvas_size.height())
if self.flip_forwards:
source = QRect(max(0, iw - width), 0, width, sh)
else:
source = QRect(0, 0, width, sh)
target = QRect(source)
target.moveLeft(0)
p.drawPixmap(target, self.after_image, source)
p.end()
示例9: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [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()
示例10: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, ev):
p = QPainter(self)
p.setOpacity(min(1, abs(1 - self._fraction)))
p.drawPixmap(self.rect(), self.icon)
p.end()
示例11: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, ev):
if self.pixmap is not None:
x = (self.width() - self.size) // 2
y = (self.height() - self.size) // 2
p = QPainter(self)
p.drawPixmap(x, y, self.size, self.size, self.pixmap)
示例12: paintEvent
# 需要导入模块: from PyQt5.Qt import QPainter [as 别名]
# 或者: from PyQt5.Qt.QPainter import drawPixmap [as 别名]
def paintEvent(self, e):
painter = QPainter(self)
h = self.pixmap.height() / 2
painter.drawPixmap(self.rect(), self.pixmap,
QRect(0, h * (1 if self.isOn else 0),
self.pixmap.width(), h))