环境设置:
Windows 11 WSL2-Ubuntu 22.04 蟒蛇 3.11.2 PySide6 6.4.3 单显示器 (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: {
root.x = root.screen.virtualX + root.screen.width / 2 - root.width / 2;
root.y = root.screen.virtualY + root.screen.height / 2 - root.height / 2;
}
TextInput{
width: 580
height: 300
horizontalAlignment: TextInput.AlignHCenter
verticalAlignment: TextInput.AlignVCenter
}
}
我尝试了每段代码here但它不起作用,每次我运行该应用程序时屏幕都处于不同的位置。