PySide6、QT、QML、WSL2:无法使窗口在中心启动

问题描述 投票:0回答:0

环境设置:

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但它不起作用,每次我运行该应用程序时屏幕都处于不同的位置。

python qt qml windows-subsystem-for-linux pyside
© www.soinside.com 2019 - 2024. All rights reserved.