Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Python go well with QML (Qt-Quick)?

I am a beginner in Qt-Quick. I am not aware of Qt which is a basis for QML. And also I'm not familiar with C++ which is again main supported language for both Qt and QML. I'm aware JS can do a lot of logic in QML layer itself. But if we need interactions with OS, then we have to use some base language. As I'm comfortable with Python, I m planning for "QML-JS-Python" combination.

So, My questions:

  1. For advanced Application and Game development Does Python & Qt-Quick do well hand in hand?
  2. Is my Combination Trio (QML-JS-Python) is good enough for this?
  3. And do I need to learn Qt for App development for coupling with Python from QML?
  4. If yes for Qust 3 then should I learn complete Qt or Only those few lines of code which stands as communication door between Python and QML?

Sorry If I'm dumb in posing these Questions. But I would like to take suggestions and opinions .

Edit: Any Limitations for this Combination QML-JS-Python

Thanks in Advance

like image 752
inblueswithu Avatar asked Mar 14 '13 09:03

inblueswithu


People also ask

Can we use QML with Python?

QML syntax also supports embedded Javascript which can be used to handle application logic -- in simple applications the entire app can be implemented in the QML! But using PyQt/PySide you can also write your application code in Python and hook this up to your QML.

What is difference between Qt and QML?

QML is the language; its JavaScript runtime is the custom V4 engine, since Qt 5.2; and Qt Quick is the 2D scene graph and the UI framework based on it. These are all part of the Qt Declarative module, while the technology is no longer called Qt Declarative.

Why Qt QML is used?

QML (Qt Markup Language) It offers a highly readable, declarative, JSON-like syntax with support for imperative JavaScript expressions, and it allows components to be easily reused and customized within a user interface. In a typical project, the front-end is developed in QML/JavaScript.

What is QML in PyQt?

QML is a declarative language that lets you develop applications faster than with traditional languages. It is ideal for designing the UI of your application because of its declarative nature. In QML, a user interface is specified as a tree of objects with properties.


1 Answers

On a conceptual level, they go together very well. I've written a python/qml/js/opengl program that combines everything fairly nicely. That was with Qt4.7 and PySide.

If you're just using QML, you can minimise the amount of Qt you'll need to be exposed to (though, as always, more knowledge makes you more powerful). Essentially, once you have a qdeclarativeview, your Qt work is done apart from the signal/slot handling, which is a joy under PySide. I would suggest that you can be productive quickly using Python and QML without worrying too much about the Qt side of things, picking it up as necessary.

From experience, I suggest making the demarcation between Python and QML clear in your own mind. I restricted the QML very much to GUI logic, which is does very well; in effect the QML handles how the interface responds to inputs, and then it sends signals back to the main program. It works a bit like creating a very basic, pared down interface between the GUI and the rest of the program, only signalling high level logic (rather than, for example, sending back a click, it would send back a signal saying for example "turn on the processing", the GUI would deal with how to render that change). In my case, this just plugged straight into my MVC framework, but you can do it how you like.

There is one big fat caveat though in all this. The development of PySide has rather stalled and currently doesn't support Qt5 and all its QML improvement goodness. There have been various discussions about how it should be supported, but not much actual code committed.

I believe PyQt supports Qt5, but dual licensed as either GPL or commercial (PySide is LGPL so can be used with closed source code). I have no experience of PyQt, other than it, and PySide being approximately drop in replacements for one-another.

It seems like I'm talking about using it as a MVVM.

(any limitations question): The whole of Qt is exposed through PySide and PyQt. This means you can write extensions in Python as you would in C. I wrote a widget that captured mouse scroll events so I could steal the scroll from a Flickable. This was a QML element created in Python, though I also had to load it from Python; I couldn't quite work out how to create an extension that I could load from inside the QML document. It's possible of course to write a C extension which is standalone to your main code, so you still always have that option.

Edit: PySide2 is now a thing and supports Qt5.

Edit2: As of 2021, Pyside is now known as QT For Python , and is very much supported up to and including QT6. Make sure you keep a note of the license.

like image 128
Henry Gomersall Avatar answered Sep 18 '22 14:09

Henry Gomersall