PDA

View Full Version : [SOLVED]How to connect different UI files



chiruL
12th September 2015, 20:49
image : 11368

Im trying to connect different Qt Dialogs using PyQt , but I can't figure out how to do that.
In my example, "dialog_inserir.ui" will be main window, so when I click "say hello !" button, the second window will appear.
How to do that in Python Qt code ?

The code im trying :




import dialog_inserir as di # the first window of image
import hello as hl # the "hello world" window
import sys
from PyQt4 import QtGui, QtCore


class MainWindow(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = di.Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButtonSayHello, QtCore.SIGNAL('clicked()'), self.Hello)

def Hello(self):
# ... what here ? ...
pass

class HelloWindow(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.helloui = hl.Ui_Dialog()
self.helloui.setupUi(self)

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mywindow = MainWindow()
mywindow.show()
sys.exit(app.exec_())

anda_skoa
12th September 2015, 20:54
probably something like this


def Hello(self):
helloWindow = HelloWindow(self)
helloWindow.show()
pass


Cheers,
_

chiruL
12th September 2015, 20:57
Oh thanks, I was missing the second 'self' arg !