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. QML: Problem with paint() function
Forum Updated to NodeBB v4.3 + New Features

QML: Problem with paint() function

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 2 Posters 5.5k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #4

    There are methods for mapping in your "base class":http://qt-project.org/doc/qt-4.8/qdeclarativeitem.html#mapFromItem.

    You can send pointers to those "empty" objects back to C++, and then do some magic there, or refactor your code so that it does not need any special data in the constructor. Then you can pass the info you need to pass when the object is completed:
    @
    Component.onCompleted: someInitMethodWrittenInNodeCpp(arguments);
    @

    Or you could get relevant data in C++ code through meta object information (like parent(), findChildren(), setProperty(), getProperty()).

    (Z(:^

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      Zaxy
      wrote on last edited by
      #5

      I didn't understand the connection between the empty QML Node objects and my instantiated objects in the model (in main.cpp)

      How to make the connection between them, how to load the custom created Node objects in main.cpp into the empty QML objects ?

      Do you have an example or something, pls ?

      Thanks a lot again

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #6

        There is no connection. Model is just a model - a bag full of data that is given to the delegate. Node is instantiated in the Delegate, and it should get the data there - through "standard QML mechanisms":http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html (by parameter name, or by model property).

        No, I don't have any example that is similar enough. I don't think I'm actually helping you that much, seems to me I'm just confusing. Sorry about that.

        (Z(:^

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zaxy
          wrote on last edited by
          #7

          you are helping me, don't worry

          Whan I want is when the QML Node object is created, the Node::paint() function in C++ must be called and draw the line.

          But with debug tracing I found that I pass through the paint() function, but, the this pointer points to an empty C++ Node object.

          So I don't understand, why call the paint() function on empty objects and how to call the paint function on the Node objects, created in the main.cpp

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #8

            My point, to put it short, is this: don't create nay node in main.cpp.

            Prepare Node c++ base class, and QML invocation so that the resulting meta object is fully configured and ready to roll.

            (Z(:^

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zaxy
              wrote on last edited by
              #9

              So QML creates an empty Object of Node class with the no-parameters constructor, calls the paint() function and later it coipes somehow the linked properties from the model ?

              I need to create the Node instances in main.cpp and configure them dynamicly and get updated the QML view. This is idea of the application I am trying to write.

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #10

                [quote author="Zaxy" date="1355317416"]So QML creates an empty Object of Node class with the no-parameters constructor, calls the paint() function and later it coipes somehow the linked properties from the model ?[/quote]

                Almost true. It instantiates the object through meta-object system. Then it assigns the properties you specify to the data read from the model, for every item in the model. Paint is called once everything is ready.

                As I've said, you could create your Nodes in main as you so much desire, but that is going to be much harder way. If I had to do it this way, I would create some null pointers in main.cpp, then, when Nodes report with Component.onCompleted, reassign those pointers to live QML objects. It's not that clean even on paper.

                (Z(:^

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  Zaxy
                  wrote on last edited by
                  #11

                  I have tried to call update() which should call paint() on Node's onCompleted with the idea that this will draw my line connection. Additionaly, I declared in the Model and Node.h Node.cpp the list _parents as a role, so that in the QML Object I should have that list too.

                  @Node {
                  id: nodeDelegate
                  x: posX
                  y: posY
                  visible: isDisplayed

                  Image{
                      id : nodeIcon
                      source: iconFilePath
                  }
                  
                  Text {
                     anchors.top: nodeIcon.bottom
                     text: nodeID
                  }
                  
                  MouseArea {
                     anchors.fill: parent
                  }
                  
                  Component.onCompleted: update();
                  

                  }@

                  but still not working ...

                  Maybe I could try to draw a line directly in QML getting info for target posX, posY from all nodes in QML property parentNodes, but don't know how to do it (the syntax)

                  What do you think ?

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    Zaxy
                    wrote on last edited by
                    #12

                    So, I think that's the idea to do it:

                    • declare additional role => parentNodes

                    in Node.qml:

                    • Component.onCompleted : { draw a line to each instance(its posX and posY) in parentNodes }

                    So what I don't know is how to write it syntaxically...

                    Do you have an idea ?

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      Zaxy
                      wrote on last edited by
                      #13

                      It should be something like this, but don't know exactly the syntax. Anyway the following example doesn't compile, but logically I want to do that:

                      @
                      Node {
                      id: nodeDelegate
                      x: posX
                      y: posY
                      visible: isDisplayed

                      Image{
                          id : nodeIcon
                          source: iconFilePath
                      }
                      
                      Text {
                         anchors.top: nodeIcon.bottom
                         text: nodeID
                      }
                      
                      MouseArea {
                         anchors.fill: parent
                      }
                      
                      Component.onCompleted: {
                          for (var i=0; i < parentNodes.count(); i++)
                          {
                              Path {
                                  startX: posX; startY: posY
                                  PathLine{x: parentNodes[i].posX ; y: parentNodes[i].posY}
                              }
                          }
                      }
                      

                      }
                      @

                      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