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:
Code:
# Create a label and set its properties
engine = QQmlApplicationEngine()
engine.
load(QUrl('QmlBackbone.qml'))win = engine.rootObjects()[0]
win.show()
sys.exit(app.exec_())
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 main.py. 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 main.py from command line python main.py, 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.
Re: What is the correct setup for developing GUI with PyQt and QML?
I think you'd have a much easier time using a Python-specific IDE, like IPython, Jupyter, or the more comprehensive Anaconda platform.
If you are working in Windows, there is also a Python IDE plugin for Visual Studio which you can get for free (along with Visual Studio Express edition itself).
Good PyQt / QtDesigner tutorial here. You should be able to adapt this once you get a good working IDE.
Re: What is the correct setup for developing GUI with PyQt and QML?
Lines 5+6 look not so good in any case.
Better just set the "visible" propery of the Window element inside the QML instead.
Cheers,
_