Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. How to integrate QGraphicsView with QML.
Forum Updated to NodeBB v4.3 + New Features

How to integrate QGraphicsView with QML.

Scheduled Pinned Locked Moved Unsolved India
5 Posts 2 Posters 8.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Praveen kk
    wrote on last edited by
    #1

    My requirement is to draw some objects, like Line, Rect, and Circle.
    I know the alternative way using Canvas, QPaintedItem etc.
    But my thought is like, if we can integrate the QGraphicsView and QGraphicsScene with QML we can have very easy handling for graphic objects (with the help of QGraphicsLineItem......etc ). I tried to integrate this with QML by exposing the class which uses QGraphicView QGraphicScene and QGraphicsLineItem but something went wrong (I dont know whether its is possible or not).

    ? 1 Reply Last reply
    0
    • P Praveen kk

      My requirement is to draw some objects, like Line, Rect, and Circle.
      I know the alternative way using Canvas, QPaintedItem etc.
      But my thought is like, if we can integrate the QGraphicsView and QGraphicsScene with QML we can have very easy handling for graphic objects (with the help of QGraphicsLineItem......etc ). I tried to integrate this with QML by exposing the class which uses QGraphicView QGraphicScene and QGraphicsLineItem but something went wrong (I dont know whether its is possible or not).

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @Praveen-kk Hi! unfortunately it's no longer possible to integrate widgets into a QtQuick scene. It was possible with QtQuick 1.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Praveen kk
        wrote on last edited by
        #3

        Thank you Wieland..!
        Any way can you tell me why they removed it from QtQuick 2. Am expecting your valuable suggestions on my issue. What is the better way to implement this kind of stuff in QML, also i may be required to save my object co-ordinates to back end database. Can you suggest me a good method to doing this.?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          QtQuick 1 was itself based on QGraphicsScene. This is why one could integrate QWidgets into a scene. The downside of this was the poor performance so QtQuick 2 was completely rewritten and has its own high-performance rendering stack which sits directly on top of OpenGL.

          Your options are...

          1. Create lines, rectangles, circles etc as QtQuick items.
          2. Create a single QQuickPaintedItem to draw lines, rectangles, circles etc.
          3. Create a single QQuickItem to draw lines, rectangles, circles etc.
          4. Use a single QtQuick Canvas item to draw lines, rectangles, circles etc.

          Option 1 is very easy to implement but performance might become an issue when you have a big number of elements. Option 2 uses QPainter as painting API and thus is easy to use but you'll have to manage all your objects by yourself and you also need to implement all user interaction by yourself. Option 3 has the best performance as you'll write your scene directly with OpenGL. Of course this is also very complicated. Option 4 makes no sense to me except if you want to avoid C++ and write your business logic in JavaScript.

          1 Reply Last reply
          2
          • P Offline
            P Offline
            Praveen kk
            wrote on last edited by
            #5

            @Wieland :

            Create lines, rectangles, circles etc as QtQuick items.
            Create a single QQuickPaintedItem to draw lines, rectangles, circles etc.
            Create a single QQuickItem to draw lines, rectangles, circles etc.

            Dear Wieland ,
            Can I get a sample for the above, Actually i am facing issue with line object. It will draw inside a rectangular area, so it is difficult to handle multiple objects.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved