本文整理汇总了Python中qtpy.QtGui.QPainter方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QPainter方法的具体用法?Python QtGui.QPainter怎么用?Python QtGui.QPainter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtGui
的用法示例。
在下文中一共展示了QtGui.QPainter方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __structure_list_context_menu
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def __structure_list_context_menu(self, point) -> None:
"""Context menu for the type synthesis results."""
index = self.structure_list.currentIndex().row()
self.to_collection.setEnabled(index > -1)
self.copy_edges.setEnabled(index > -1)
self.copy_image.setEnabled(index > -1)
action = self.pop_menu_topo.exec_(self.structure_list.mapToGlobal(point))
if not action:
return
clipboard = QApplication.clipboard()
if action == self.to_collection:
self.add_collection(self.answer[index].edges)
elif action == self.copy_edges:
clipboard.setText(str(self.answer[index].edges))
elif action == self.copy_image:
# Turn the transparent background to white.
image1 = self.__atlas_image()
image2 = QImage(image1.size(), image1.format())
image2.fill(Qt.white)
painter = QPainter(image2)
painter.drawImage(QPointF(0, 0), image1)
painter.end()
clipboard.setPixmap(QPixmap.fromImage(image2))
示例2: paintEvent
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def paintEvent(self, event):
edit = self.edit
height = edit.fontMetrics().height()
block = edit.firstVisibleBlock()
count = block.blockNumber()
painter = QPainter(self)
painter.fillRect(event.rect(), edit.palette().base())
first = True
while block.isValid():
count += 1
block_top = edit.blockBoundingGeometry(block).translated(
edit.contentOffset()).top()
if not block.isVisible() or block_top > event.rect().bottom():
break
rect = QRect(0, block_top, self.width(), height)
self.draw_block(painter, rect, block, first)
first = False
block = block.next()
painter.end()
super(PromptArea, self).paintEvent(event)
示例3: generatePicture
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def generatePicture(self,data=None,redraw=False):
"""重新生成图形对象"""
# 重画或者只更新最后一个K线
if redraw:
self.pictures = []
elif self.pictures:
self.pictures.pop()
w = 0.4
bPen = self.bPen
bBrush = self.bBrush
rPen = self.rPen
rBrush = self.rBrush
self.low,self.high = (np.min(data['low']),np.max(data['high'])) if len(data)>0 else (0,1)
npic = len(self.pictures)
for (t, open0, close0, low0, high0) in data:
if t >= npic:
picture = QtGui.QPicture()
p = QtGui.QPainter(picture)
# 下跌蓝色(实心), 上涨红色(空心)
pen,brush,pmin,pmax = (bPen,bBrush,close0,open0)\
if open0 > close0 else (rPen,rBrush,open0,close0)
p.setPen(pen)
p.setBrush(brush)
# 画K线方块和上下影线
if open0 == close0:
p.drawLine(QtCore.QPointF(t-w,open0), QtCore.QPointF(t+w, close0))
else:
p.drawRect(QtCore.QRectF(t-w, open0, w*2, close0-open0))
if pmin > low0:
p.drawLine(QtCore.QPointF(t,low0), QtCore.QPointF(t, pmin))
if high0 > pmax:
p.drawLine(QtCore.QPointF(t,pmax), QtCore.QPointF(t, high0))
p.end()
self.pictures.append(picture)
# 手动重画
#----------------------------------------------------------------------
示例4: createPic
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def createPic(self,xmin,xmax):
picture = QPicture()
p = QPainter(picture)
[pic.play(p) for pic in self.pictures[xmin:xmax]]
p.end()
return picture
# 定义边界
#----------------------------------------------------------------------
示例5: assert_pyside
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def assert_pyside():
"""
Make sure that we are using PySide
"""
import PySide
assert QtCore.QEvent is PySide.QtCore.QEvent
assert QtGui.QPainter is PySide.QtGui.QPainter
assert QtWidgets.QWidget is PySide.QtGui.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PySide.QtWebKit.QWebPage
示例6: assert_pyside2
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def assert_pyside2():
"""
Make sure that we are using PySide
"""
import PySide2
assert QtCore.QEvent is PySide2.QtCore.QEvent
assert QtGui.QPainter is PySide2.QtGui.QPainter
assert QtWidgets.QWidget is PySide2.QtWidgets.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PySide2.QtWebEngineWidgets.QWebEnginePage
示例7: assert_pyqt4
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def assert_pyqt4():
"""
Make sure that we are using PyQt4
"""
import PyQt4
assert QtCore.QEvent is PyQt4.QtCore.QEvent
assert QtGui.QPainter is PyQt4.QtGui.QPainter
assert QtWidgets.QWidget is PyQt4.QtGui.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PyQt4.QtWebKit.QWebPage
示例8: assert_pyqt5
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def assert_pyqt5():
"""
Make sure that we are using PyQt5
"""
import PyQt5
assert QtCore.QEvent is PyQt5.QtCore.QEvent
assert QtGui.QPainter is PyQt5.QtGui.QPainter
assert QtWidgets.QWidget is PyQt5.QtWidgets.QWidget
if QtWebEngineWidgets.WEBENGINE:
assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebEngineWidgets.QWebEnginePage
else:
assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebKitWidgets.QWebPage
示例9: square_pixmap
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def square_pixmap(size):
"""Create a white/black hollow square pixmap. For use as labels cursor."""
pixmap = QPixmap(QSize(size, size))
pixmap.fill(Qt.transparent)
painter = QPainter(pixmap)
painter.setPen(Qt.white)
painter.drawRect(0, 0, size - 1, size - 1)
painter.setPen(Qt.black)
painter.drawRect(1, 1, size - 3, size - 3)
painter.end()
return pixmap
示例10: drag_with_pixmap
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def drag_with_pixmap(list_widget: QListWidget) -> QDrag:
"""Create a QDrag object with a pixmap of the currently select list item.
This method is useful when you have a QListWidget that displays custom
widgets for each QListWidgetItem instance in the list (usually by calling
``QListWidget.setItemWidget(item, widget)``). When used in a
``QListWidget.startDrag`` method, this function creates a QDrag object that
shows an image of the item being dragged (rather than an empty rectangle).
Parameters
----------
list_widget : QListWidget
The QListWidget for which to create a QDrag object.
Returns
-------
QDrag
A QDrag instance with a pixmap of the currently selected item.
Example
-------
>>> class QListWidget:
... def startDrag(self, supportedActions):
... drag = drag_with_pixmap(self)
... drag.exec_(supportedActions, Qt.MoveAction)
"""
drag = QDrag(list_widget)
drag.setMimeData(list_widget.mimeData(list_widget.selectedItems()))
size = list_widget.viewport().visibleRegion().boundingRect().size()
pixmap = QPixmap(size)
pixmap.fill(Qt.transparent)
painter = QPainter(pixmap)
for index in list_widget.selectedIndexes():
rect = list_widget.visualRect(index)
painter.drawPixmap(rect, list_widget.viewport().grab(rect))
painter.end()
drag.setPixmap(pixmap)
drag.setHotSpot(list_widget.viewport().mapFromGlobal(QCursor.pos()))
return drag
示例11: paintEvent
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def paintEvent(self, event):
"""Paint the colorbox. If no color, display a checkerboard pattern.
Parameters
----------
event : qtpy.QtCore.QEvent
Event from the Qt context.
"""
painter = QPainter(self)
if self.layer._selected_color is None:
for i in range(self._height // 4):
for j in range(self._height // 4):
if (i % 2 == 0 and j % 2 == 0) or (
i % 2 == 1 and j % 2 == 1
):
painter.setPen(QColor(230, 230, 230))
painter.setBrush(QColor(230, 230, 230))
else:
painter.setPen(QColor(25, 25, 25))
painter.setBrush(QColor(25, 25, 25))
painter.drawRect(i * 4, j * 4, 5, 5)
else:
color = 255 * self.layer._selected_color
color = color.astype(int)
painter.setPen(QColor(*list(color)))
painter.setBrush(QColor(*list(color)))
painter.drawRect(0, 0, self._height, self._height)
示例12: __save_atlas
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def __save_atlas(self) -> None:
"""Save function as same as type synthesis widget."""
count = self.collection_list.count()
if count < 1:
return
lateral, ok = QInputDialog.getInt(
self,
"Atlas",
"The number of lateral:",
5, 1
)
if not ok:
return
file_name = self.output_to("atlas image", qt_image_format)
if not file_name:
return
icon_size = self.collection_list.iconSize()
width = icon_size.width()
image = self.collection_list.item(0).icon().pixmap(icon_size).toImage()
image_main = QImage(QSize(
lateral if count > lateral else count,
(count // lateral) + bool(count % lateral)
) * width, image.format())
image_main.fill(Qt.transparent)
painter = QPainter(image_main)
for row in range(count):
image = self.collection_list.item(row).icon().pixmap(icon_size).toImage()
painter.drawImage(QPointF(row % lateral, row // lateral) * width, image)
painter.end()
pixmap = QPixmap()
pixmap.convertFromImage(image_main)
pixmap.save(file_name)
self.save_reply_box("Atlas", file_name)
示例13: __save_atlas
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def __save_atlas(self) -> None:
"""Saving all the atlas to image file.
We should turn transparent background to white first.
Then using QImage class to merge into one image.
"""
count = self.structure_list.count()
if count < 1:
return
lateral = self.__save_atlas_ask()
if not lateral:
return
file_name = self.output_to("atlas image", qt_image_format)
if not file_name:
return
width = self.structure_list.iconSize().width()
image_main = QImage(QSize(
lateral * width if count > lateral else count * width,
((count // lateral) + bool(count % lateral)) * width
), self.__atlas_image(0).format())
image_main.fill(Qt.transparent)
painter = QPainter(image_main)
for row in range(count):
image = self.__atlas_image(row)
painter.drawImage(QPointF(row % lateral, row // lateral) * width, image)
painter.end()
pixmap = QPixmap.fromImage(image_main)
pixmap.save(file_name)
self.save_reply_box("Atlas", file_name)
示例14: svg_to_image
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QPainter [as 别名]
def svg_to_image(string, size=None):
""" Convert a SVG document to a QImage.
Parameters
----------
string : basestring
A Python string containing a SVG document.
size : QSize, optional
The size of the image that is produced. If not specified, the SVG
document's default size is used.
Raises
------
ValueError
If an invalid SVG string is provided.
Returns
-------
A QImage of format QImage.Format_ARGB32.
"""
if isinstance(string, unicode_type):
string = string.encode('utf-8')
renderer = QtSvg.QSvgRenderer(QtCore.QByteArray(string))
if not renderer.isValid():
raise ValueError('Invalid SVG data.')
if size is None:
size = renderer.defaultSize()
image = QtGui.QImage(size, QtGui.QImage.Format_ARGB32)
image.fill(0)
painter = QtGui.QPainter(image)
renderer.render(painter)
return image