Issue
I need to call a form(custom dialog designed with QtDesigner) through the slot of a button on the Main Window(also on QtDesigned, hence seperate file). Below is the relevant code:
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.btn.clicked.connect(self.my_func)
def my_func(self):
form = Form_UI.Custom_Dialog()
if form.exec_():
print "successfully opened"
How ever I get the following error:
Traceback (most recent call last):
File "F:\myPath\code.py", line 27, in my_func
if form.exec_():
AttributeError: 'Custom_Dialog' object has no attribute 'exec_'
I don't understand, because the following code(using built-in Dialog) works just fine:
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.btn.clicked.connect(self.my_func)
def my_func(self):
form = QtGui.QDialog()
if form.exec_():
print "successfully opened"
Any help would be appreciated. Thanks in advance.
Solution
The class generated by pyuic4
does not derive from QDialog
, so if you don't write a python class for that ui file as you did for the main window, you need to create a QDialog
object and a ui class object:
def my_func(self):
form = QtGui.QDialog()
ui_form = Form_UI.Custom_Dialog()
ui_form.setupUi(form)
if form.exec_():
print "successfully opened"
Answered By - alexisdm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.