Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Best practice drawing lines
Forum Updated to NodeBB v4.3 + New Features

Best practice drawing lines

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtquick2linesdrawing
5 Posts 4 Posters 1.0k 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.
  • E Offline
    E Offline
    Edwin_martens
    wrote on last edited by
    #1

    For a QtQuick project I need a "rendering window" where I can draw custom 2D points and lines. And I have to be able to add those lines and object consisting of those lines (snapes) dynamically from C++.

    I could use QPaintedItem which is easy but seems to be slow. Using QQuickwindow and QquickItem should be a lot faster. I understand how to define a derived version of those in C++. But all examples add one or more static graphic objects in the QML.
    I need the graphic objects to be able to be added dynamically (runtime that is) to the scene.

    Any suggestions?
    And are there any books about this ?

    Yours sincerely,
    Edwin Martens

    jeremy_kJ 1 Reply Last reply
    0
    • E Edwin_martens

      For a QtQuick project I need a "rendering window" where I can draw custom 2D points and lines. And I have to be able to add those lines and object consisting of those lines (snapes) dynamically from C++.

      I could use QPaintedItem which is easy but seems to be slow. Using QQuickwindow and QquickItem should be a lot faster. I understand how to define a derived version of those in C++. But all examples add one or more static graphic objects in the QML.
      I need the graphic objects to be able to be added dynamically (runtime that is) to the scene.

      Any suggestions?
      And are there any books about this ?

      Yours sincerely,
      Edwin Martens

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by jeremy_k
      #2

      @Edwin_martens said in Best practice drawing lines:

      For a QtQuick project I need a "rendering window" where I can draw custom 2D points and lines. And I have to be able to add those lines and object consisting of those lines (snapes) dynamically from C++.

      Have you looked at the Canvas item? It does not have a public C++ interface beyond what QQuickItem provides, but that may be sufficient.

      I could use QPaintedItem which is easy but seems to be slow.

      I'm presuming this is supposed to be QQuickPaintedItem, which forces work to be done in the GUI thread. That could be a problem. Have you profiled to determine what part is slow?

      Using QQuickwindow and QquickItem should be a lot faster. I understand how to define a derived version of those in C++. But all examples add one or more static graphic objects in the QML.
      I need the graphic objects to be able to be added dynamically (runtime that is) to the scene.

      The handler for this dynamic behavior can call QQuickItem::update() to schedule a redraw, or it can modify a property used in a display-related binding.

      Any suggestions?
      And are there any books about this ?

      There's a post pinned at the top of the QML and Quick section that discusses general performance issues using the scene graph. I think there are some blog posts about Qt Skinny (Quick with QML) that are performance oriented. I haven't see anything book length with this particular narrow focus.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0
      • johngodJ Offline
        johngodJ Offline
        johngod
        wrote on last edited by
        #3

        I have done something like that using Qt Quick 3D, its blazing fast since it runs on gpu. I have used QQuick3DGeometry (c++), to define lines, it can be used also for points, then I have export it to qml. Then creating lines (or points) at runtime it is done like any qml Item, using createComponent(). If you want have a pick on my project. Qml line: https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/qml/qmlEntities/Line.qml and the c++ QQuick3DGeometry custom line https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/entities/entity_line.h .
        Also there was a video online not sure if from some qt blog post about drawing huge insane amount of points using Qt quick 3D but I cant find it right now.

        GrecKoG 1 Reply Last reply
        0
        • johngodJ johngod

          I have done something like that using Qt Quick 3D, its blazing fast since it runs on gpu. I have used QQuick3DGeometry (c++), to define lines, it can be used also for points, then I have export it to qml. Then creating lines (or points) at runtime it is done like any qml Item, using createComponent(). If you want have a pick on my project. Qml line: https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/qml/qmlEntities/Line.qml and the c++ QQuick3DGeometry custom line https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/entities/entity_line.h .
          Also there was a video online not sure if from some qt blog post about drawing huge insane amount of points using Qt quick 3D but I cant find it right now.

          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          You could use a Repeater to instantiate lines and points dynamically by providing a c++ model. If you do need to not render everything you could add a filter model on top.

          johngodJ 1 Reply Last reply
          0
          • GrecKoG GrecKo

            You could use a Repeater to instantiate lines and points dynamically by providing a c++ model. If you do need to not render everything you could add a filter model on top.

            johngodJ Offline
            johngodJ Offline
            johngod
            wrote on last edited by
            #5

            @GrecKo Thanks for the tips.
            Initially I had a QList with c++ objects, but now for simplicity I am trying to avoid that. To manage the dynamic objects, each has a signal connection when they are created. Then when something happens, they receive signals and each object manage it self (turns visible, unvisible, gets deleted, ....). I think this approach it is much easier than creating filters and lists or repeaters.

            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