Mixing QML GUI and GraphicsView painting



  • Hi,

    I want to write something like a game for children. The background shall be something like a cheat of paper.
    The users can paint on it like in Scribble. Additionally they can insert elements like shapes and more complex elements modeled in Qml. Last but not least it wouldl be great to add Flash content as well.

    I guess I have to use a QGraphicsView / ~scene and insert the Qml elements as GraphicsItem, so that it is possible to zoom in and out, change the z-order of the elements, so that the paintings can lay above as well as under the Qml elements. Am not sure if Flash can be handled in the same way.

    Is the direction right or am I missing something? Do you have maybe some additional hints or links about this topic? I just used Google too, but without the right questions it is difficult to get the right answers :)

    Thanks in advance!
    Micha



  • You could mix QML into your graphics scene or equally valid you could you QGraphicsView on its own.



  • Thanks for the short reply. But there is still one question open (ok, I didn't mention it in my first post):
    If I do it the opposite way ... exporting GraphicsItems to QML ... can I export there ex. lines too (e.g. from PathStroke example)?



  • To be honest I am not sure how you would go about having an item you can paint on within QML - well I have a very vague notion but it is so vague it is not worth mentioning.

    I would go for QGraphicsView/Scene for this application. Just use QGraphicsPixmapItem (or svg based item) for your pre-defined shapes etc.



  • Hmmm ... thanks for the answer. Would the new QML scene graph resolve this problem?



  • I think not specifically. I think it is doable with a custom QML item but not trivial. You would need a custom item that would need to track mouse movements following a mouse down event. During the drag your custom item would need to adjust its bounding rect as well as keep painting itself.

    Since you will be doing all this in the C++ side of things anyway I just suggested doing the whole scene management in QGraphicsView.



  • Thank you for the new replay :)
    The approach you mentioned doesn't sound bad, even it would be a little bit of work :)
    Do you know probably a project, link or something like this for a follow up study?



  • I would start by trying to port the "Scribble":http://doc.qt.nokia.com/latest/widgets-scribble-scribblearea-h.html example that ships with Qt to QGraphicsView and take it from there.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.