get mainwindow size?
-
-
All windows can be obtained from QGuiApplication::allWindows(). The main window can be found with a loop over all windows. Then its size can be obtained.
Is there any easier way to get mainwindow size of a Qt app? I need it deep in my Qt app.
@JoeCFD
In a word, "No". If you need to access the main window (or any other window) from deep down in code you do need a helper function like you have found. You can make yours (maybe) a bit faster: I usedQGuiApplication::topLevelWindows()for top-level only (no parent) as that will be what main window is, I don't know if Qt can produce that faster thanallWindows().I found it fine, speed-wise. Of course if you do it a lot you could always cache the result fur re-use.
I prefer this to saving some "globally accessible variable" which you set with the main window when you first create it. But of course that would be fast.
-
All windows can be obtained from QGuiApplication::allWindows(). The main window can be found with a loop over all windows. Then its size can be obtained.
Is there any easier way to get mainwindow size of a Qt app? I need it deep in my Qt app.
-
@JoeCFD
Hi.
I never did this, but a possible workaround is:In your virtual void QMainWindow::resizeEvent(QResizeEvent *event); you can store the size of application in variables where all your code can access them.
It is only an idea! :)
-
@JoeCFD
In a word, "No". If you need to access the main window (or any other window) from deep down in code you do need a helper function like you have found. You can make yours (maybe) a bit faster: I usedQGuiApplication::topLevelWindows()for top-level only (no parent) as that will be what main window is, I don't know if Qt can produce that faster thanallWindows().I found it fine, speed-wise. Of course if you do it a lot you could always cache the result fur re-use.
I prefer this to saving some "globally accessible variable" which you set with the main window when you first create it. But of course that would be fast.
-
Hi,
Out of curiosity, why do you need that information deep in your code ?