Important: Please read the Qt Code of Conduct -

How to acces MainWindow objects from QGraphicsItem

  • Hello again,

    I have an application where my main window contains a toolbar with buttons on it, a left menu QFrame with QLabel objects, and a central area of type QGraphicsScene where I drag and drop QGraphicsItems. Each one of those QGraphicsItems has an object of type QDialog that shows up when double clicking on the Item... when the dialog appears it contains a QGLWidget that will plot a mathematical function of mine (and here is my problem...) only when the button "Run" located in the toolbar of the MainWindow is clicked.
    So my question is, how do I read the status of the button "Run" located in the toolbar of the main window from within the dialog of a QGraphicsItem?

    Thanks for your suggestions,


  • You could use some global status cache, or signals and slots to set the state from run button via MainWindow to the objects.

    Please do yourself a favor and don't try to access the button from the dialogs.

    I would use:

    run button connect to a slot in MainWindow and state stored there.

    give dialog a pointer to the main window and call a getter method there.

    Or create a custom QApplication derived class and store the state there. The global QApplication object can be used from all obejcts.

  • Hi Gerolf,

    thanks for the tips, I like number 1, seems easy to do and I thought about that before but still my problem was how to read the state of "run" button stored in MainWindow from inside a dialog class of a QGraphicsItem inside a QGraphicsScene. Can you give me some help there too? Thanks.

Log in to reply