QWidget showFullScreen 产生多个 resizeEvents

发布于 2024-12-18 04:21:52 字数 1442 浏览 2 评论 0原文

我有一个使用 PySide 用 python 编写的 QT 应用程序,我偶然发现了一个关于 QGLWidget 的 showFullScreen 方法的小问题(尽管这个问题也出现在所有其他小部件上):

问题是,该小部件没有它的“最终” ' 程序从 showFullScreen 返回后的分辨率。 该开关似乎是在 5 到 10 毫秒后异步触发的。

这对我来说是一个问题,因为我必须进行一些布局计算,这取决于小部件显示后的大小。

下面是一个小重现器,它是 QGLWidget 的子类。使用此重现器,您会注意到,在 showFullScreen 之后 resizeEvent 将被调用两次。

我正在寻找一种方便的方法来了解哪个 resizeEvent 是“最终”事件,或者一种了解小部件何时真正处于全屏模式的方法。有没有我可以连接的信号?

非常感谢您对此的任何帮助。

#!/usr/bin/python

import sys
from PySide.QtGui import QApplication
from PySide.QtCore import QTimer
from PySide.QtOpenGL import QGLWidget

class TestWidget(QGLWidget):
    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self._timer = QTimer()
        self._timer.setInterval(5)
        self._timer.timeout.connect(self.showsize)
        self._timer.start()

    def resizeEvent(self, event):
        print "Resize event:", event.size().width(), event.size().height()

    def showsize(self):
        w = widget.size().width()
        print "Timer: ", w, widget.size().height()
        if w == 1680:
           self._timer.stop()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = TestWidget()
    widget.showFullScreen()
    print "After showFullScreen:", widget.size().width(), widget.size().height()
    # this will always be 640 480...1680 1050 is what I'm expecting
    app.exec_()

I have a QT application written in python using PySide and I stumbled across a little problem regarding the showFullScreen method of the QGLWidget (although the problem occurs with every other widget too):

The problem is, that the widget doesn't have its 'final' resolution after the program returns from showFullScreen.
The switch seems to be triggered asynchronously between 5 and 10 milliseconds later.

This is a problem for me because I have to do some layout calculations which depend on the widget's size after it is shown.

Below is a little reproducer which subclasses QGLWidget. Using this reproducer you will take notice, that resizeEvent will be called twice after showFullScreen.

I'm looking for a convinient way of knowing which resizeEvent is the 'final' one, or a way of knowing, when the widget really is in fullscreen mode. Is there maybe any signals I could connect to?

Thanks a lot for any help on this.

#!/usr/bin/python

import sys
from PySide.QtGui import QApplication
from PySide.QtCore import QTimer
from PySide.QtOpenGL import QGLWidget

class TestWidget(QGLWidget):
    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self._timer = QTimer()
        self._timer.setInterval(5)
        self._timer.timeout.connect(self.showsize)
        self._timer.start()

    def resizeEvent(self, event):
        print "Resize event:", event.size().width(), event.size().height()

    def showsize(self):
        w = widget.size().width()
        print "Timer: ", w, widget.size().height()
        if w == 1680:
           self._timer.stop()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = TestWidget()
    widget.showFullScreen()
    print "After showFullScreen:", widget.size().width(), widget.size().height()
    # this will always be 640 480...1680 1050 is what I'm expecting
    app.exec_()

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

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

发布评论

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

评论(1

年华零落成诗 2024-12-25 04:21:52

一种可能性是检查调整大小事件是否自发或不是。从此处的有限测试(在 Linux 上使用 Qt C++)来看,第二个调整大小事件是自发的,而第一个则不是。

只有当事件是自发的时你才能进行计算。

注意:我不确定它的便携性如何,这可能取决于您的窗口管理器/窗口系统。

One possibility is to check that if the resize event is spontaneous or not. From limited testing here (using Qt C++ on Linux), the second resize event is spontaneous, while the first one is not.

You could do your calculations only when the event is spontaneous.

Note: I'm not sure how portable this is, it might depend on your window manager/windowing system.

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