0

I have a complex project that relies heavily on QGraphicsScene and QGraphicsItem. Different, detailed implementations for multiple types of items, and complex interactions between items on the scene have been carefully designed. The UI around and including the view is created with QWidgets.

The new requirement is to replace all QWidgets with a QML front end. I am trying to figure out how to do it. I read multiple posts, suggesting solutions:

  1. Throw away the QGraphicItems and paint pretty squares on a QML scene (as this answer suggests). This may be fine for starting a new project, but not great considering how much work would take, if even possible.
  2. Use QtQuick 1, which supported QGraphicsScene integration (as this answer suggests). Does not seem ideal to be stuck with an old version.
  3. "Make the QGraphicsItems into QGraphicsObjects and expose them to QML." (Placing QGraphicsScene within a QML UI?). This looks most promising but there are no details... I would love to know how to to this.
  4. Use QQuickWidget somehow, I am trying to figure it out right now based on this Qt Quick Widgets Example, not getting anywhere though because each "subwindow" is fully separate from all the others.

Please help me find a way to integrate a QGraphicsScene / QGraphicsView in the middle of a qml widget, so that I can keep the old functionality with minimal changes, but change the front end to be full QML. An example would be awesome.

Thalia
  • 13,637
  • 22
  • 96
  • 190
  • Currently not possible. So you will have to use option number 1 – eyllanesc Feb 18 '20 at 18:16
  • @eyllanesc If you can't think of a solution to this problem, why close my question instead of letting others give suggestions ? – Thalia Feb 18 '20 at 18:35
  • Your question has been asked many times in SO and the answer is always the same: It is not possible. And the same is indicated by the duplicate question. The SO rules state that if there is a duplicate question, it must be voted to close and that is what I have done. – eyllanesc Feb 18 '20 at 18:43
  • 1
    If you at all can, stick with QGraphicsScene stuff for this kind of legacy project. Unless there is some hard requirement, like some embedded platform where you *require* that QSceneGraph goodness for adequate performance, then porting that kind of an app to QML is not the best idea. Start a project to develop a new version of the app "from scratch" instead, obviously copying the business logic parts of the old app where appropriate. And start by testing how to do the more difficult parts of current app with QML, in throw-away PoC projects. Also, consider aiming for Qt6, if possible. – hyde Feb 18 '20 at 18:50
  • I disagree with @eyllanesc: this question is not the same as the proposed as duplicated. This question is about the migration of QGraphicsItems and QGraphicsScene (which was directly usable in QtQuyick1 as a QML object) to QtQuick2, that is not based in QGraphicsScene. You misunderstood that OP was asking for embedding QWidgets in QML, and that is not what I understand. – Former contributor Feb 18 '20 at 18:51
  • ...Also, working that Qt6 angle may give you leverage to postpone the whole migration to QML. Some food for thought: https://www.qt.io/blog/2019/08/07/technical-vision-qt-6 – hyde Feb 18 '20 at 18:59
  • @Thalia: I am in a very similar quest with my (not so complex) desktop project [vmpk](https://sourceforge.net/p/vmpk/code/HEAD/tree/trunk/desktop/). The piano keyboard is a QGraphicsScene, with each key being a QGraphicsItem. It was easy to adapt a [QML/Qt4 version](https://sourceforge.net/p/vmpk/code/HEAD/tree/trunk/mobile/) for the Nokia N9/N950 phone, because QtQuick1 was very compatible. I've migrated the desktop part to Qt5 long ago, but not to QML yet. I would probably use the QQuickPaintedItem route, or wait a little more... – Former contributor Feb 18 '20 at 19:10
  • 1
    Thank you all, I am researching how long it would take to implement my `QGraphicsItems` in QML, and the difficulties I may encounter. Apart from the backwards compatibility issues (e.g. the `QTextDocument` and `QFontMetrics` affecting the accuracy of text item sizing and positions etc), and some relationships between items, I believe it is possible that porting everything to QML may be beneficial. – Thalia Feb 18 '20 at 19:36

0 Answers0