Important: Please read the Qt Code of Conduct -

PyQt QMainWindow

  • Good, please, how do I open a single instance of a QMainWindow ?, that is, only when there is no instance of that type of QMainWindow.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    As silly as it may sound: create it only once.

    For a more complete answer, please provide more details about your use case.

  • Example: I have three classes that inherit from QMainWindow called: UnityIndex, ArticleIndex and InvoicingIndex, I want a single instance of each class to be executed, that is, the instance is executed only when it is not active and if it is already active, do not execute a new instance, and that allows me to execute the three classes but with a single instance.

  • @henry5059
    You can't. Also, you don't "execute classes, or even instances of classes". So "allows me to execute the three classes but with a single instance" doesn't mean a lot to me.

    Purely at a guess, perhaps you are talking about needing a QStackedWidget so as to show only one widget at time from among multiple widgets.

    Separately, why you would want to have more than one instance of a QMainWindow anywhere in your program I do not know. Usually you are best with one main window, nothing else needs to have QMainWindow style.

  • @JonB Okay, thanks for the info

Log in to reply