QML - main window position on start (screen center)

AntyaDev picture AntyaDev · Jan 23, 2012 · Viewed 12.5k times · Source

How I can do following: I’d like show my main window on start on the center screen.

Answer

Dielson Sales picture Dielson Sales · Jul 27, 2014

If using QtQuick, it's possible to do that:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.0

ApplicationWindow {
    visible: true
    width: 320
    height: 480
    Component.onCompleted: {
        // Commenting this to use properties instead of setters
        //setX(Screen.width / 2 - width / 2);
        //setY(Screen.height / 2 - height / 2);
        x = Screen.width / 2 - width / 2
        y = Screen.height / 2 - height / 2
    }
}