本文整理汇总了Python中AnyQt.QtGui.QPixmap.grabWindow方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.grabWindow方法的具体用法?Python QPixmap.grabWindow怎么用?Python QPixmap.grabWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.grabWindow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import grabWindow [as 别名]
def __init__(self, parent=None):
super().__init__(parent, Qt.CustomizeWindowHint | Qt.FramelessWindowHint | Qt.Window |
Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint)
self.setAttribute(Qt.WA_DeleteOnClose)
self.installEventFilter(self)
self.setMouseTracking(True)
self._band = QRubberBand(QRubberBand.Rectangle, self)
self._resize_origin = None
self._drag_mask = 0
self._origin = None
self.selected_image = None
# Window background
desktop = QApplication.desktop()
if is_qt5():
g = desktop.geometry()
self._snapshot = QPixmap(g.width(), g.height())
painter = QPainter(self._snapshot)
for screen in QApplication.screens():
g = screen.geometry()
painter.drawPixmap(g, screen.grabWindow(0, g.x(), g.y(), g.width(), g.height()))
painter.end()
else:
self._snapshot = QPixmap.grabWindow(desktop.winId(), 0, 0, desktop.width(), desktop.height())
self.setGeometry(desktop.geometry())
self._darken = self._snapshot.copy()
painter = QPainter(self._darken)
brush = QBrush(QColor(0, 0, 0, 128))
painter.setBrush(brush)
painter.drawRect(self._darken.rect())
painter.end()
# Buttons
self._buttons = QWidget(self)
self._button_layout = QHBoxLayout(self._buttons)
self._button_layout.setSpacing(0)
self._button_layout.setContentsMargins(0, 0, 0, 0)
self._button_layout.setContentsMargins(0, 0, 0, 0)
self.save_as = QPushButton(self.tr('Save As'))
self.save_as.pressed.connect(self.save_image_as)
self.save_as.setCursor(Qt.ArrowCursor)
self._button_layout.addWidget(self.save_as)
self.copy = QPushButton(self.tr('Copy'))
self.copy.pressed.connect(self.copy_to_clipboard)
self.copy.setCursor(Qt.ArrowCursor)
self._button_layout.addWidget(self.copy)
self.share = QPushButton(self.tr('Share'))
self.share.pressed.connect(self.share_selection)
self.share.setCursor(Qt.ArrowCursor)
self._button_layout.addWidget(self.share)
self._buttons.hide()