Use Qt Design Studio QML with PySide2

人盡茶涼 提交于 2020-03-16 09:16:49

问题


I am new to Qt Designer Studio. I just created a simple button in Qt Design Studio and I am trying to use the QML file with PySide2 but I am getting multiple import errors. Is there a specific way to implement Qt Design Studio qml files with PySide2.

The project name is Demo that I created in Qt Design Studio

The Demo Project structure:

   Demo.qml
   Demo.qmlproject
   Demo.qmlproject.qtds
   imports
   qtquickcontrols2.conf
   Screen01.ui.qml

The PySide2 project structure (main.py files includes the code):

   Demo.qml
   Demo.qmlproject
   Demo.qmlproject.qtds
   imports
   qtquickcontrols2.conf
   Screen01.ui.qml
   main.py

main.py:

from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtQuick import QQuickView
from PySide2.QtCore import QUrl
from imports import QtQuick
app = QApplication([])
view = QQuickView()
url = QUrl("Screen01.ui.qml")
view.engine().addImportPath("imports")
view.setSource(url)
view.show()
app.exec_()

Error:

module "QtStudio3D" is not installed 
module "Qt.SafeRenderer" is not installed 

Screen01.ui.qml

import QtQuick 2.12
import Demo 1.0
import QtQuick.Controls 2.3

Rectangle {
    width: Constants.width
    height: Constants.height

    color: Constants.backgroundColor

    Button {
        id: nameButton
        x: 136
        y: 227
        text: qsTr("Button")
    }
}

来源:https://stackoverflow.com/questions/60237780/use-qt-design-studio-qml-with-pyside2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!