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
QtWS25 Last Chance

QML: Problem with paint() function

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 2 Posters 5.5k 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.
  • Z Offline
    Z Offline
    Zaxy
    wrote on 12 Dec 2012, 10:57 last edited by
    #3

    How could I make the connection between the empty created classes in QML when paint() is called and my instanciated Node objects in main.cpp. So QML creates three empty Node objects (there are three Nodes in the List Model), call the paint function and them fill them with values from the model ?

    Maybe I can define a copyconstructor in Node.cpp and call inside the paint function or even update() ?

    About the coordinates, no idea how to map them ... Could you please give me some example ?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 12 Dec 2012, 11:11 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 12 Dec 2012, 11:51 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
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 12 Dec 2012, 11:57 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 12 Dec 2012, 12:05 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
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 12 Dec 2012, 12:40 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 12 Dec 2012, 13:03 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
                • S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 12 Dec 2012, 13:11 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 12 Dec 2012, 13:56 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 12 Dec 2012, 14:09 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 12 Dec 2012, 15:53 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

                        12/13

                        12 Dec 2012, 14:09

                        • Login

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