我对Qt还比较陌生。我在Gtk3中构建了一些东西,包括内省和gladeui设计器。你知道吗
现在,我在努力学习PyQt。虽然我喜欢它如何使您的Ui成为一个类(对我来说似乎更容易管理),但有些事情让我困惑。当我用-x
(create executable file)标志运行pyuic4
时,它有以下代码位:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_multippp(object):
def setupUi(self, multippp):
multippp.setObjectName(_fromUtf8("multippp"))
multippp.resize(371, 43)
self.verticalLayout = QtGui.QVBoxLayout(multippp)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.label = QtGui.QLabel(multippp)
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout.addWidget(self.label)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout.addLayout(self.verticalLayout_2)
self.retranslateUi(multippp)
QtCore.QMetaObject.connectSlotsByName(multippp)
def retranslateUi(self, multippp):
multippp.setWindowTitle(QtGui.QApplication.translate("multippp", "Multiple PPP Accounts", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("multippp", "More than one PPP account found, please select one:", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
multippp = QtGui.QDialog()
ui = Ui_multippp()
ui.setupUi(multippp)
multippp.show()
sys.exit(app.exec_())
在这段(生成的)代码中,我试图理解的是,为什么multippp对话框不是所有其他小部件的类的一部分。相反,据我所知,你递给它一个QDialog,它将它塑造成你想要的样子。把QDialog分开有什么好处吗?如果有,那有什么好处?你知道吗
子小部件需要一个小部件容器,比如QMainWindow或QDialog。不过,您也可以将小部件用作顶级小部件。QDialog之所以存在,是因为pyuic4不知道您计划如何使用这个设计好的小部件。你知道吗
在您的程序中,QDialog可以是任何其他小部件容器。也可以将multippp子类化。你知道吗
要完成,QDialog只是执行代码的父级。
相关问题 更多 >
编程相关推荐