【问题标题】:How to convert qml to python3 with pyuic5?如何使用 pyuic5 将 qml 转换为 python3?
【发布时间】:2016-03-22 19:55:25
【问题描述】:

我在 Qt5 上使用 QtCreator3。我使用 qml 设计了一个 UI。现在我想使用 pyuic5 将其转换为 python3。我该怎么办?

mygui.qml

import QtQuick 2.0

Rectangle {
    width: 360
    height: 360
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }

        Image {
            id: image1
            x: 130
            y: 130
            width: 100
            height: 100
            fillMode: Image.PreserveAspectFit
            source: "microphono_logo.jpg"
        }

        Text {
            id: text1
            x: 133
            y: 281
            text: qsTr("Click & Speak")
            font.family: "Times New Roman"
            font.pixelSize: 16
        }
    }
}

【问题讨论】:

  • 我对QML不是很熟悉,但是我觉得uic/pyuic不会把QML作为输入。他们采用.ui 文件,这些文件是由Qt 设计器生成的XML 文件。
  • 是的,我明白了。但是你知道如何将 qml 转换为 xml 到 ui 吗?
  • 你不应该将 qml 转换为 python,就像 pyuic 一样。 QML 旨在由 python 代码直接加载。请参阅此示例 - pyqt.sourceforge.net/Docs/PyQt5/qml.html#ref-integrating-qml
  • 该示例实际上并没有告诉您如何将 Qml 与 PyQt5 一起使用。问题是组件从 Qt4 更改为 Qt5。这是一个适用于 Qt4 的示例 - wiki.qt.io/PySide-and-QML-Playground

标签: qt python-3.x pyqt5


【解决方案1】:

首先,您必须将您设计的文件保存为QT Design Studio中的.qml文件,然后用QT creator打开.qml文件> 并保存为 .ui

最后,您可以使用以下语法将ui文件转换为py文件

pyuic5 -o mygui.py mygui.ui

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 2018-10-27
    • 2021-07-10
    • 2019-03-05
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多