PyQt显示全屏图像

发布于 2024-08-10 19:05:43 字数 145 浏览 4 评论 0原文

我正在使用 PyQt 使用 QPixmap.grabWindow(QApplication.desktop().winId()) 捕获我的屏幕,我想知道是否有一种方法可以全屏显示我的 screengrab(没有窗口边框等)我试图找到一种方法来使用 PyQt 降低显示器的饱和度

I'm using PyQt to capture my screen with QPixmap.grabWindow(QApplication.desktop().winId()) and I was wondering if there was a way I could display my screengrab fullscreen (no window borders, etc.) I'm trying to find a way to desaturate my display with PyQt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

注定孤独终老 2024-08-17 19:05:43

通过将 QtCore.Qt.FramelessWindowHint 传递给 QWidget 构造函数,与图像小部件代码中的 self.showFullScreen() 实现这一点。

Passing QtCore.Qt.FramelessWindowHint to the QWidget constructor in symphony with self.showFullScreen() in the image widget's code achieves this.

踏雪无痕 2024-08-17 19:05:43

directedition 描述的解决方案的 PyQt6 工作示例。

  • Qt.WindowType.FramelessWindowHint 生成无边框窗口,doc
    注意,它可以作为构造函数中的 flags 参数传递,也可以使用 setWindowFlags
  • showFullScreen() 以全屏模式显示小部件, doc
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QImage
from PyQt6.QtWidgets import QApplication, QMainWindow


class Img(QMainWindow):
    def __init__(self, img_path, parent=None):
        super().__init__(parent)
        self.qimg = QImage(img_path)

        self.setWindowFlags(Qt.WindowType.FramelessWindowHint) 

    def paintEvent(self, qpaint_event):
        # event handler of QWidget triggered when, for ex, painting on the widget’s background.
        painter = QPainter(self)
        rect = qpaint_event.rect() # Returns the rectangle that needs to be updated
        painter.drawImage(rect, self.qimg)
        self.showFullScreen()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    
    img_path = # add path of the image

    window = Img(img_path)
    window.show()
    
    sys.exit(app.exec())

A PyQt6 working example of the solution as described by directedition.

  • Qt.WindowType.FramelessWindowHint produces a borderless window, doc.
    Notice that it can be either passed as flags argument in the constructor or fixed in a second moment with setWindowFlags
  • showFullScreen() shows the widget in full-screen mode, doc
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QImage
from PyQt6.QtWidgets import QApplication, QMainWindow


class Img(QMainWindow):
    def __init__(self, img_path, parent=None):
        super().__init__(parent)
        self.qimg = QImage(img_path)

        self.setWindowFlags(Qt.WindowType.FramelessWindowHint) 

    def paintEvent(self, qpaint_event):
        # event handler of QWidget triggered when, for ex, painting on the widget’s background.
        painter = QPainter(self)
        rect = qpaint_event.rect() # Returns the rectangle that needs to be updated
        painter.drawImage(rect, self.qimg)
        self.showFullScreen()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    
    img_path = # add path of the image

    window = Img(img_path)
    window.show()
    
    sys.exit(app.exec())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文