作为标题,我使用
self.connect(MorePushButton, SIGNAL("clicked"), MorePushButton_toggled)
和
self.connect(MorePushButton, SIGNAL("clicked"), self.MoreFrame.setVisible)
执行函数“MorePushButton_toggled”并在点击MorePushButton时设置属性。
但是,这是我无法弄清楚的问题: 当我按下按钮 MorePushButton 时,它什么也没做! 它也没有错误信息。 我把代码放错了吗? 如果有人可以帮助我,我将不胜感激!
以下是我的代码:
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui_extention2 import Ui_Dialog
class Main(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.connect(MorePushButton, SIGNAL("clicked"), MorePushButton_toggled)
self.connect(MorePushButton, SIGNAL("clicked"), self.MoreFrame.setVisible)
self.setupUi(self)
def MorePushButton_toggled(self):
if self.MorePushButton.isChecked() == True:
#self.Dialog.setGeometry(QtCore.QRect(0,0,400,280))
Dialog.resize(400, 280)
print("Resize 400*280")
else:
#self.Dialog.setGeometry(QtCore.QRect(0,0,400,100))
Dialog.resize(400, 100)
print("Resize 400*100")
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
注: (1).ui文件由QT Designer设计 (2)Python版本:4.3 (3)PyQt版本:GPL 4.11.4