查看完整版本: [-- 恢复PyQt5的QWidgets所有子类自动显示功能 --]

QTCN开发网 -> Python Qt GUI快速编程 -> 恢复PyQt5的QWidgets所有子类自动显示功能 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

jearchen 2018-04-27 15:04

恢复PyQt5的QWidgets所有子类自动显示功能

昨晚上,在eric6下面把一个正常的MainWindow的ui文件编译成.py文件。打开代码,在里面加了一句self.menubar.hide(),之后我其他所有的.py文件的按钮啊,QLabel啊所有的QWidgets子类全部不能显示,具体看下面的代码:

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class window(QWidget):
    def __init__(self,parent=None):
        super(window,self).__init__(parent)
        self.setWindowTitle("QMessage例子")
        self.resize(300,200)                
        self.signal1 =pyqtSignal()
        self.signal2 = pyqtSignal()        
       self.btn1=QPushButton("按钮1")
        self.btn2=QPushButton("按钮2")        
        self.btn1.clicked.connect(self.messageMention1)
        self.btn2.clicked.connect(self.messageMention2)
        layout =QVBoxLayout()
        layout.addWidget(self.btn1)
        layout.addWidget(self.btn2)
        self.setLayout= (layout)


    def messageMention1(self):
            reply=QMessageBox.information(self,"点击啦","按了第一个按钮,我收到了",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
            print(reply)
    def messageMention2(self):
            QMessageBox.information(self,"点击啦 ","按下了第二个按钮 ,我收到了",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
if __name__=="__main__":
    app = QApplication(sys.argv)
    myshow=window()
    myshow.show()
    sys.exit(app.exec_())
效果图见图[attachment=18828]



jearchen 2018-04-27 15:17
self.setLayout=layout改成self.setLayout(layout)


查看完整版本: [-- 恢复PyQt5的QWidgets所有子类自动显示功能 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled