0

I have a QDialog which is a login window. When the login is successful, I would like to open my MainWindow from QMainWindow class. I have herited my QMainWidnow from a UI_file generated with QtDesigner.

To be more specific, I have the following:

login.py:

from PyQt4 import QtCore, QtGui
from main import ciras_main
class Ui_Dialog(object):
    def setupUi(self, Dialog):
    ....
    def retranslateUi(self, Dialog):
    ....
def welcomeWindowShow(self, username):
    self.welcomeWindow = QtGui.QMainWindow()
    self.ui = ciras_main(username)
    self.ui.setupUi(self.welcomeWindow, username)
    self.welcomeWindow.show()

ui_main.py:

from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
    def setupUi(self, MainWindow, username):
    ...
    def retranslateUi(self, MainWindow):
    ...

and my main class herited from ui_main.py

from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QDialog
from ui_main import *
class ciras_main(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self,username, parent=None):
        super(ciras_main, self).__init__(parent)
        self.setupUi(self, username)
        self.comboBox.activated.connect(self.selectProject)
        ...
    def selectProject(self):
        ...

The problem is the following. When login is successful, function welcomeWindowShow() is called to open my Mainwindow from class ciras_main. However, it seems it only loads ui_main.py because the function "selectProject" for example (when i change my combobox) does not execute anything. However, If I execute my mainwindow without passing by login.py, everything works. I think my problem is to connect the welcomeWindowShow() function to open my mainwindow.

Any idea about why it s not working? Thank you very much

froz
  • 163
  • 1
  • 12
  • try `self.welcomeWindow.exec()` instead of `self.welcomeWindow.show()` – Jonas Oct 01 '18 at 12:36
  • Unfortunately it does not work, saying that QMainWindow has no attribute exec() – froz Oct 01 '18 at 12:41
  • Does QDialog die after welcomeWindowShow? Python uses reference counting and the only saved reference to "ui" is in QDialog. If QDialog dies the "ui" may die either in python or the C++ side. – justengel Oct 01 '18 at 12:48
  • After self.welcomeWindow.show(), i execute Dialog.close(). However, the welcomewindow stays visible – froz Oct 01 '18 at 13:09
  • `ciras_main` inherits from `QMainWindow` but you construct another `QMainWindow`... `welcomeWindow` and `ui` are both instances of `QMainwindow` – Jonas Oct 01 '18 at 13:18
  • If i understand well, I construct an object QMainWindows instead of ciras_main? How can I change it? – froz Oct 01 '18 at 13:21
  • Ok, with your comment I understood my mistake. I have to put in the function welcomeWindowShow the following: def welcomeWindowShow(self, username): self.welcomeWindow = ciras_main(username) self.welcomeWindow.show() It seems it is working! Thank you – froz Oct 01 '18 at 13:23

0 Answers0