Environment setup:
Windows 11 WSL2 - Ubuntu 22.04 Python 3.11.2 PySide6 6.4.3 Single Monitor (2560x1440)
main_file.py:
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
app = QGuiApplication()
engine = QQmlApplicationEngine()
engine.load("qmls/mainscreen.qml")
app.exec()
qmls/mainscreen.qml
import QtQuick
import QtQuick.Controls
Window {
id: root
visible: true
width: 320
height: 480
Component.onCompleted: {
var x_calc = (root.Screen.width / 2) - (root.width / 2)
var y_calc = (root.Screen.height / 2) - (root.height / 2)
root.x = x_calc
root.y = y_calc
}
TextInput{
width: 580
height: 300
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
}
}
I tried every piece of code here and it isn't working, every time i run the app the screen is in a different position.