I\'ve created two windows using qt4 designer, and would like to link them together. I put them both in a folder and created a file outside the directory, which I\'m importing th
You really need to reconsider the design of your application.
Opening and closing multiple main windows in the manner you describe is ugly and completely unnecessary. Instead, you should have one main window and use a QStackedWidget to hold a sequence of pages that can navigated through using buttons.
To experiment with this idea, create a new main window in Qt Designer and add a QStackedWidget to it (it's in the "Containers" section). Then open the two UIs you've already designed, and copy the widgets of each UI into separate pages of the stacked-widget.
Once you've done that, make sure you give all the widgets descriptive names, because you will need to refer to them later when you start writing the logic for your program. The main script of your application should look something like this:
from PyQt4 import QtCore, QtGui
from mainwindow_ui import Ui_MainWindow
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
...
self.buttonNext.clicked.connect(self.handleButtonNext)
self.buttonPrev.clicked.connect(self.handleButtonPrev)
def handleButtonNext(self):
index = self.stackedWidget.currentIndex() + 1
if index < self.stackedWidget.count():
self.stackedWidget.setCurrentWidget(index)
def handleButtonPrev(self):
index = self.stackedWidget.currentIndex() - 1
if index >= 0:
self.stackedWidget.setCurrentWidget(index)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Obviously, the real logic for your program will be more sophisticated than this, but it should give you a general idea of how to go about things.
PS:
I have never used it myself, but you might also want to see if the QWizard class might be more suitable for your needs.