在pyqt中最大化窗口大小时无法隐藏窗口 [英] Cant't hide a window when window size maximized in pyqt

查看:45
本文介绍了在pyqt中最大化窗口大小时无法隐藏窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个窗口,我想在三秒后使用 Qt 计时器隐藏它,但它重叠......它可能发生在窗口大小设置为显示最大化"

i have two windows,i want to hide it after three seconds by using Qt timer,but its overlapping...its probably occurs when window size sets to "showMaximized"

from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from PyQt4.QtCore import Qt, QPoint

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)



class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.showMaximized()
        Form.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
        self.label = QtGui.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(450, 317, 300, 61))
        self.label.setStyleSheet(_fromUtf8("font: 75 60pt \"Tlwg Mono\";color: rgb(255, 255, 255);"))
        self.label.setObjectName(_fromUtf8("label"))

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))
        self.label.setText(_translate("Form", "omniOS", None))

class Ui_Dialog1(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.showMaximized()
        Dialog.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.centralwidget = QtGui.QWidget(Dialog)
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))


class Dialog(QtGui.QDialog, Ui_Form):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)
        self.setupUi(self)

class Dialog1(QtGui.QDialog, Ui_Dialog1):
    def __init__(self, parent=None):
        super(Dialog1, self).__init__(parent)
        self.setupUi(self)
    def paintEvent(self, event):
         painter = QtGui.QPainter(self)
         painter.setPen(QtGui.QPen(QtCore.Qt.white))
         painter.drawArc(QtCore.QRectF(640, 330, 35, 35), 0, 5750)



if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    w1=Dialog()
    w2=Dialog1()




    def on_timeout():
        w1.hide()
        w2.show()

    QtCore.QTimer.singleShot(3000, on_timeout)
    sys.exit(app.exec_())

我需要做的是,我需要得到三秒后的第二个窗口大小设置为最大化.

what I need to do is, I need to get second window after three seconds when size sets to maximized.

 Form.showMaximized()

对 (form.resize) 的更改符合我的预期.任何帮助请

This change to (form.resize) its working what i expected. Any help plz

推荐答案

你没有观察到 w1 是关闭的,因为 w2 高于 w1,但是如果它有效,那么你在评论中指出我理解你最初想要仅可见 w1,3 秒后显示 w2,隐藏 w1,考虑到解决方案如下:

You do not observe that w1 is closed because w2 is above w1, but if it is working, so you point out in the comments I understand that you want initially only visible w1 and after 3 seconds w2 is displayed and w1 is hidden, considering that the solution is the following:

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    w1=Dialog()
    w2=Dialog1()
    w2.hide()
    QtCore.QTimer.singleShot(3000, w1.hide)
    QtCore.QTimer.singleShot(3000, w2.showMaximized)
    sys.exit(app.exec_())

这篇关于在pyqt中最大化窗口大小时无法隐藏窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆