Ryan
Ryan

Reputation: 289

Can't seem to call a custom dialog from the mainWindow. PySide

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.

Upvotes: 0

Views: 1392

Answers (1)

alexisdm
alexisdm

Reputation: 29896

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"

Upvotes: 1

Related Questions