Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get Qt application window size from a QML file which is not the QML where the root window is declared?

While I am in a random QML file which is not the parent main.qml, is it possible to get the Qt application window size?

I know that I can declare the app window root in a global property like below and get the size anywhere.

ApplicationWindow {
    id: main_window_root
    visible: true
    width: 1000
    height: 800

    property alias main_window_root: main_window_root
}

But my primary question is, does Qt itself have a global property declared which can fetch the application window size?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I ask this because I see that I can get the application state, platform it is running on etc by doing a Qt. in any QML file. It looks like some properties are globally declared by Qt. Following is official documentation for this:
https://doc.qt.io/qt-5/qml-qtqml-qt.html

Hence the question, is the application window size also accessible through some global property in QML?

I am using Qt 5.15.8 commercial version.

>Solution :

ApplicationWindow is a Window, which provides attached properties to read the width and height. So you can use Window.width and Window.height from anywhere to get the current window’s dimensions. See docs here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading