SamuelNLP
SamuelNLP

Reputation: 4136

Display a popup window before the mainwindow runs

How can I make a popup window that appears before the mainwindow begins? I want the popup to have several QLineEdit widgets to receive input that I will need for the mainwindow. I searched for solutions, but I could not understand most of the examples I found. Can some one help me?

Upvotes: 0

Views: 1329

Answers (1)

Eric Hulser
Eric Hulser

Reputation: 4022

Just make a subclass of QDialog, execute it modally before running your normal startup logic.

Thats how I did it for an app that required a login, worked just fine. This would be the general idea in Python (it takes me less time to think about it in PyQt):

import sys

from PyQt4 import QtGui, QtCore
from mymodule import MyDialog, MyWindow

def main(argv):
    app = QtGui.QApplication(argv)

    # make a dialog that runs in its own event loop
    dlg = MyDialog()
    if ( not dlg.exec_() ):  # in C++, this would be dlg->exec()
        sys.exit(0)

    var1, var2, var3 = dlg.values()        

    window = MyWindow()
    window.setPropertyOne(var1)
    window.setPropertyTwo(var2)
    window.setPropertyThree(var3)
    window.show()

    sys.exit(app.exec_())

if ( __name__ == '__main__' ):
    main(sys.argv)

Upvotes: 1

Related Questions