本文整理匯總了Python中PySide.QtGui.QPainter方法的典型用法代碼示例。如果您正苦於以下問題:Python QtGui.QPainter方法的具體用法?Python QtGui.QPainter怎麽用?Python QtGui.QPainter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PySide.QtGui
的用法示例。
在下文中一共展示了QtGui.QPainter方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lineNumberAreaPaintEvent
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def lineNumberAreaPaintEvent(self, event):
painter = QPainter(self.lineNumberArea)
painter.fillRect(event.rect(), Qt.lightGray)
block = self.firstVisibleBlock()
blockNumber = block.blockNumber()
top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
bottom = top + self.blockBoundingRect(block).height()
while (block.isValid() and top <= event.rect().bottom()):
if (block.isValid and bottom >= event.rect().top()):
number = str(blockNumber + 1)
painter.setPen(QtCore.Qt.black)
painter.drawText(0, top, self.lineNumberArea.width(),
self.fontMetrics().height(),
QtCore.Qt.AlignCenter, number)
block = block.next()
top = bottom
bottom = top + self.blockBoundingRect(block).height()
blockNumber += 1
示例2: getIcon
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def getIcon(obj,disabled=False,path=None):
if not path:
path = iconPath
if not getattr(obj,'_icon',None):
obj._icon = addIconToFCAD(obj._iconName,path)
if not disabled:
return obj._icon
if not getattr(obj,'_iconDisabled',None):
name = getattr(obj,'_iconDisabledName',None)
if name:
obj._iconDisabled = addIconToFCAD(name,path)
else:
key = os.path.join(path,obj._iconName) + '.disabled'
fmt = None
try:
if FreeCADGui.isIconCached(key):
obj._iconDisabled = key
return key
else:
fmt = 'PNG'
except Exception:
pass
pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize,mode=QIcon.Disabled)
icon = QIcon(pixmapDisabled)
icon.paint(QPainter(pixmap),0,0,iconSize[0],iconSize[1],Qt.AlignCenter)
data = QByteArray()
buf = QBuffer(data)
buf.open(QIODevice.WriteOnly)
if fmt:
pixmap.save(buf, fmt)
FreeCADGui.addIcon(key,data.data(),fmt)
else:
pixmap.save(buf, 'XPM')
key = data.data().decode('latin1')
obj._iconDisabled = key
return obj._iconDisabled
示例3: get_icon
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def get_icon(icon, size=24):
"""get svg icon from icon resources folder as a pixel map
"""
img = get_icon_path("{}.svg".format(icon))
svg_renderer = QtSvg.QSvgRenderer(img)
image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32)
# Set the ARGB to 0 to prevent rendering artifacts
image.fill(0x00000000)
svg_renderer.render(QtGui.QPainter(image))
pixmap = QtGui.QPixmap.fromImage(image)
return pixmap
示例4: _paint_points
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def _paint_points(self, img, points):
painter = QtGui.QPainter(img)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0))
pen.setWidth(0)
painter.setPen(pen)
for point in points:
self._paint_point(painter, *point)
painter.end()
示例5: get_QPainter
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def get_QPainter():
"""QPainter getter."""
try:
import PySide.QtGui as QtGui
return QtGui.QPainter
except ImportError:
import PyQt5.QtGui as QtGui
return QtGui.QPainter
示例6: numberbarPaint
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def numberbarPaint(self, number_bar, event):
font_metrics = self.fontMetrics()
current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
block = self.firstVisibleBlock()
line_count = block.blockNumber()
painter = QtGui.QPainter(number_bar)
painter.fillRect(event.rect(), self.palette().base())
# Iterate over all visible text blocks in the document.
while block.isValid():
line_count += 1
block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
# Check if the position of the block is out side of the visible
# area.
if not block.isVisible() or block_top >= event.rect().bottom():
break
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
font.setBold(True)
painter.setFont(font)
else:
font = painter.font()
font.setBold(False)
painter.setFont(font)
# Draw the line number right justified at the position of the line.
paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
painter.drawText(paint_rect, QtCore.Qt.AlignRight, unicode(line_count))
block = block.next()
painter.end()
示例7: paintEvent
# 需要導入模塊: from PySide import QtGui [as 別名]
# 或者: from PySide.QtGui import QPainter [as 別名]
def paintEvent(self, e):
painter = QtGui.QPainter()
painter.begin(self)
self.drawBars(painter)
painter.end()