Important: Please read the Qt Code of Conduct -

What is the correct setup for developing GUI with PyQt and QML?

  • Hello,

    I am looking for advice on developing PyQt QML applications. More specifically, I would like to know what setup and working mode ensures the smoothest progress.

    I have been trying to write a GUI using the following:

    In Eclipse IDE with PyDev, I create a new PyDev project. My main .py file launches a QML application:

    app = QApplication(sys.argv)
         # Create a label and set its properties
         engine = QQmlApplicationEngine()
         win = engine.rootObjects()[0]

    The QML application is defined in a .qml file, which I create by right-clicking my PyDev project and clicking on 'add new file'. I name this file 'QmlBackbone.qml'. When the file is created, QtCreator automatically loads up, since I have given the file a .qml extension. There I can modify the QML structure.

    I launch the application from Eclipse, by running This works if there is no error in my .qml files. If there is any error, the application exits at win = engine.rootObjects()[0] (because, most probably, engine.load(QUrl('QmlBackbone.qml')) fails, so engine has not root objects), without logging any errors in QtCreator. I am left trying to guess what causes the error, which drastically amplifies the debug time.

    Another disadvantage is that I do not see a Project structure in QtCreator. Thus, I can only access .qml files from the 'Open Documents' box, provided I opened them before from Eclipse.

    In other words, QtCreator just works as a QML code editor - nothing else.

    Additionally, if I run from command line python, I get the following error, which I do not get when I launch from Eclipse:

    ImportError: No module named PyQt5.QtCore

    I feel like my approach is completely off-track and unproductive.

    How should I plan to develop a GUI using PyQt? Which tools should I use? What is the default recommended workflow? Should I create a project within QtCreator? Creating a project from QtCreator assumes I am using C++, but I am using Python.

  • Lifetime Qt Champion


    From the looks of it, you don't have PyQt5 in your python path when using the console. Your IDE likely takes care of that for you.

  • Lifetime Qt Champion

    @dhb285 Do you use Python only to load QML and the rest of your application is just that QML? If so, why using Python at all?

  • I am also wondering whether it is possible and makes sense to mix pyqt and QML. For example, I want to develop a custom diagraming tool with special symbols and rules, and don't want to plugins in C++. Maybe that's what he is after...

  • Lifetime Qt Champion

    @patrickkidd Well, if the whole application is QML and Python is only used to load that QML then I don't see the need for Python. Just use C++ : it will be just one main.cpp loading the QML :-)
    I know that you can connect C++ and QML but I don't think there is a direct connection between Python and QML. You most probably will need to write some C++ code to connect you Python code and QML, but then you can just use C++.

  • @jsulm thank you for your response. I suppose I am wondering more about whether QML/JavaScript can provide the same level of customization as C++ or python (which ever of the latter probably doesn't matter). I have another thread posted about this:

    How to Organize Custom Diagraming Project with PyQt

  • Lifetime Qt Champion

    @patrickkidd If customization means UI in this context then QML is for sure more flexible and customizable than C++/Widgets.

  • Maybe it is coincidence but I just started on a personal project that also requires this type of information. At this point I am coding everything, the Python and QML code by hand in notepadd++ but was wondering about all of this.

    My reasoning for integrating PyQt and QML: I have an external Python library that I want to create a GUI for so decided to use QML. I have basically no Python experience, and only a bit of QML . I am quite comfortable with Qt C++ but could not find a easy way to make the Python library available to Qt C++ (without boost or something). So I see this as a good challenge and learning opportunity since I also have another QML project I want to start.

    I am using the following links as references, it seems like mixing Python and QML is already well supported using PyQt:

    In conclusion, I also want to know what tools can be recommended and some workflow guidance.

Log in to reply