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. Visualization of dynamic c++ list with positions as set of Items in QML-app at corresponding positions.
QtWS25 Last Chance

Visualization of dynamic c++ list with positions as set of Items in QML-app at corresponding positions.

Scheduled Pinned Locked Moved QML and Qt Quick
qmllistc++exposing qmldata visualizat
12 Posts 2 Posters 4.1k Views
  • 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.
  • I Offline
    I Offline
    ilyaik
    wrote on 28 Mar 2015, 11:57 last edited by ilyaik 4 Jan 2015, 07:43
    #1

    Some c++ class periodically sends a list of items with positions inside (x and y). It needs to be visualized on grids and axis I've created in QML.
    For representation of item I've prepared black rectangle in Rect.qml file.
    Is it possible to:

    • represent each item using rect.qml (like appearance of item)
    • not using paint(...) from QQuickPaintedItem and updatePaintNode(...) from QQuickItem respectively
    • place each item in some QML container (like Rectangle) with corresponding (x and y) from list ?
      I didn't find any straight way to do this.

    I know i could use QGraphicsScene and QPainter with QMainWindow GUI without any "qml" but i want to use benefits of QML interface.

    P 1 Reply Last reply 28 Mar 2015, 12:44
    0
    • I ilyaik
      28 Mar 2015, 11:57

      Some c++ class periodically sends a list of items with positions inside (x and y). It needs to be visualized on grids and axis I've created in QML.
      For representation of item I've prepared black rectangle in Rect.qml file.
      Is it possible to:

      • represent each item using rect.qml (like appearance of item)
      • not using paint(...) from QQuickPaintedItem and updatePaintNode(...) from QQuickItem respectively
      • place each item in some QML container (like Rectangle) with corresponding (x and y) from list ?
        I didn't find any straight way to do this.

      I know i could use QGraphicsScene and QPainter with QMainWindow GUI without any "qml" but i want to use benefits of QML interface.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 28 Mar 2015, 12:44 last edited by
      #2

      @ilyaik How does the list of items look like ?
      One way to implement would be using Connections. Set the target as your C++ class which I assume you have set as a context property. Then when ever the new list is sent through as signal, grab it inside the corresponding handler in QML. Once you get the list iterate over it and then set x and y coordinates of the Black rectangles. For this you can keep a list of Black rectangles in QML array.

      157

      I 1 Reply Last reply 28 Mar 2015, 13:09
      1
      • P p3c0
        28 Mar 2015, 12:44

        @ilyaik How does the list of items look like ?
        One way to implement would be using Connections. Set the target as your C++ class which I assume you have set as a context property. Then when ever the new list is sent through as signal, grab it inside the corresponding handler in QML. Once you get the list iterate over it and then set x and y coordinates of the Black rectangles. For this you can keep a list of Black rectangles in QML array.

        I Offline
        I Offline
        ilyaik
        wrote on 28 Mar 2015, 13:09 last edited by
        #3

        @p3c0 This is an idea!
        List is a QList<struct {int x; int y}>

        But as it always happens... after 1 day of searching solution appears only after asking a question on forum =)

        I did as you said: a C++ class myList with QList inside. I made this class as a context property. Class has Q_PROPERTY (int count READ count NOTIFY countChanged) that is the size of QList.
        In QML part i've placed

        Repeater { 
           model: myList.count;
           Rectangle {
              // black rectangle
                ...
                x: myList.xPosition(index)
                y: myList.yPosition(index)
           }
        }
        

        myList has xPosition(index) and yPosition(index) slots recpectively.

        And it works.
        Thank you for help!

        P 1 Reply Last reply 28 Mar 2015, 13:16
        0
        • I ilyaik
          28 Mar 2015, 13:09

          @p3c0 This is an idea!
          List is a QList<struct {int x; int y}>

          But as it always happens... after 1 day of searching solution appears only after asking a question on forum =)

          I did as you said: a C++ class myList with QList inside. I made this class as a context property. Class has Q_PROPERTY (int count READ count NOTIFY countChanged) that is the size of QList.
          In QML part i've placed

          Repeater { 
             model: myList.count;
             Rectangle {
                // black rectangle
                  ...
                  x: myList.xPosition(index)
                  y: myList.yPosition(index)
             }
          }
          

          myList has xPosition(index) and yPosition(index) slots recpectively.

          And it works.
          Thank you for help!

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 28 Mar 2015, 13:16 last edited by
          #4

          @ilyaik You're Welcome :)
          Using Repeater is also a good idea. You can mark the post as solved if done.

          157

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ilyaik
            wrote on 1 Apr 2015, 07:43 last edited by
            #5

            I've faces a new problem.

            If QList inside myClass changed it's values, but count myList.count didn't, Repeater doesn't updates. That's ok... strictly speaking the Repeater's model myList.count didn't change.
            I made a signal from myClass updateSignal. updateSignal emits when data inside list in myClass is updated. In QML this signal is exposed in Connections part.

            Connections {
                    target: myClass
                    onUpdateSignal {
                        repeater.model = 0
                        repeater.model = myClass.count
                    }
            }
            
            // And Repeater part
            
            Repeater { 
                id: repeater
                model: 0
                Rectangle {
                  // black rectangle
                    ...
                    x: myList.xPosition(index)
                    y: myList.yPosition(index)
                }
            }
            

            It renewsrepeater.
            But it seams that it's like a crutch.
            Is there any proper way to renew Repeater?

            P.S. repeater.update() didn't help.

            P 1 Reply Last reply 1 Apr 2015, 09:18
            0
            • I ilyaik
              1 Apr 2015, 07:43

              I've faces a new problem.

              If QList inside myClass changed it's values, but count myList.count didn't, Repeater doesn't updates. That's ok... strictly speaking the Repeater's model myList.count didn't change.
              I made a signal from myClass updateSignal. updateSignal emits when data inside list in myClass is updated. In QML this signal is exposed in Connections part.

              Connections {
                      target: myClass
                      onUpdateSignal {
                          repeater.model = 0
                          repeater.model = myClass.count
                      }
              }
              
              // And Repeater part
              
              Repeater { 
                  id: repeater
                  model: 0
                  Rectangle {
                    // black rectangle
                      ...
                      x: myList.xPosition(index)
                      y: myList.yPosition(index)
                  }
              }
              

              It renewsrepeater.
              But it seams that it's like a crutch.
              Is there any proper way to renew Repeater?

              P.S. repeater.update() didn't help.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 1 Apr 2015, 09:18 last edited by
              #6

              @ilyaik That is a valid way. Bindings are meant for that.
              Also it should work even without first assigning model to 0 in Connections.

              157

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ilyaik
                wrote on 1 Apr 2015, 10:21 last edited by
                #7

                No. Repeater doesn't renew without assigning model to 0 in Connections. It seems like nothing changes for Repeater if myClass.count stays unchanged.

                P 1 Reply Last reply 1 Apr 2015, 10:34
                0
                • I ilyaik
                  1 Apr 2015, 10:21

                  No. Repeater doesn't renew without assigning model to 0 in Connections. It seems like nothing changes for Repeater if myClass.count stays unchanged.

                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 1 Apr 2015, 10:34 last edited by
                  #8

                  @ilyaik That means the count didnot change

                  repeater.model = myClass.count
                  

                  the Repeater will update only when the property changes. That is how Binding works.

                  157

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    ilyaik
                    wrote on 1 Apr 2015, 10:47 last edited by
                    #9

                    So that's why i use assigning model to 0 in Connections to force Repeater to renew itself when count stays unchanged.

                    P 1 Reply Last reply 1 Apr 2015, 10:50
                    0
                    • I ilyaik
                      1 Apr 2015, 10:47

                      So that's why i use assigning model to 0 in Connections to force Repeater to renew itself when count stays unchanged.

                      P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 1 Apr 2015, 10:50 last edited by
                      #10

                      @ilyaik Ok. So is it that you only want to update x and y positions even if no new item is added ?

                      157

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        ilyaik
                        wrote on 1 Apr 2015, 14:18 last edited by
                        #11

                        Yes. If myClass's QList changes inside

                        P 1 Reply Last reply 2 Apr 2015, 05:37
                        0
                        • I ilyaik
                          1 Apr 2015, 14:18

                          Yes. If myClass's QList changes inside

                          P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 2 Apr 2015, 05:37 last edited by
                          #12

                          @ilyaik then I think my first post could be the possible way.

                          157

                          1 Reply Last reply
                          0

                          10/12

                          1 Apr 2015, 10:50

                          • Login

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