1

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")
    }
}

2 Answers2

0

Use PyQt and Qt Designer to create a UI

Artem
  • 1
0

For ppl stumbling here with googling i got main window to show properly with:

import sys
import os

from PySide2.QtCore import Qt, QObject, Signal, Slot, Property
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine

if __name__ == "__main__":
    app = QGuiApplication(sys.argv)
     
    engine = QQmlApplicationEngine()
    engine.addImportPath("imports")
    print(engine.importPathList() )
    engine.load('qttest2.qml')
    
    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(app.exec_())

And the file qttest2.qml is from qt design studio, containing (had to edit manually for the main window):

import QtQuick 2.12
import QtQuick.Layouts 1.3
import qttest2 1.0
import QtQuick.Controls 2.12

ApplicationWindow {
  visible: true
  width: 800
  height: 500
  Item {
    width: Constants.width
    height: Constants.height

    Screen01 {
    }
  }
}
susundberg
  • 650
  • 7
  • 14