我只是想创建一个小应用程序,它在按下按钮时打开另一个对话框。以下是对话框的代码。创建一个返回参数的自定义对话框
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(508, 300)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(150, 250, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 120, 181, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.label.setFont(font)
self.label.setObjectName("label")
self.sl_value = QtGui.QSlider(Dialog)
self.sl_value.setGeometry(QtCore.QRect(220, 120, 161, 31))
self.sl_value.setOrientation(QtCore.Qt.Horizontal)
self.sl_value.setObjectName("sl_value")
self.ed_value = QtGui.QLineEdit(Dialog)
self.ed_value.setGeometry(QtCore.QRect(400, 120, 41, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.ed_value.setFont(font)
self.ed_value.setObjectName("ed_value")
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "Set example value:", None, QtGui.QApplication.UnicodeUTF8))
而在主文件我已经添加下面的代码段
class StartSub2(QtGui.QDialog, Ui_Dialog):
def __init__(self,parent=None):
QtGui.QDialog.__init__(self,parent)
self.setupUi(self)
dlg = StartSub2()
if dlg.exec_():
values = dlg.getValues()
每当按下按钮时打开的对话框但是对话的是元件的完全空没有被示出。 那么如何让元素在对话框中可见? 但是,当我尝试导入主文件对话框的文件我收到错误
cannot import name Ui_Dialog
你可以表现出你所得到的 – eyllanesc
你的代码已经发布的作品对我来说非常精细的图像。我只需要在创建对话框之前添加'app = QtGui.QApplication([])''。 – ekhumoro