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. Extending QML - When is the parent set?
Forum Updated to NodeBB v4.3 + New Features

Extending QML - When is the parent set?

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 7 Posters 5.4k 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.
  • B Offline
    B Offline
    bundickt
    wrote on last edited by
    #1

    I'm writing a QML C++ extension class and need to do something with the parent during initialization of my object. I have noticed that in the constructor parent is null, but sometime later parent is set. I am trying to find something I can connect to that will tell me either when the parent is set or right before the Componet.onCompleted signal is emitted.

    Looking through the qt source it looks like I can override componentComplete if I inherit from QDeclarativeItem, but I am not creating an item that needs to be draw so I inherit from QObject. Is it possible to do this inheriting from QObject or do I have to inherit from QDeclarativeItem, or is there another way of doing this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Matahari
      wrote on last edited by
      #2

      Have you look around setParent function? Maybe you can overload it.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bundickt
        wrote on last edited by
        #3

        setParent isn't a virtual functions so overriding it won't work in this case.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tipiak
          wrote on last edited by
          #4

          QDeclarativeItem is not drawn by default unless you set "ItemHasNoContenst" like this somewhere in your constructor :
          setFlag(QGraphicsItem::ItemHasNoContents, false);

          .signature

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="Tipiak" date="1300290488"]QDeclarativeItem is not drawn by default unless you set "ItemHasNoContenst" like this somewhere in your constructor :
            setFlag(QGraphicsItem::ItemHasNoContents, false);
            [/quote]

            As far as I know, the ItemHasNoContents flag is not set by default. By default, an item will be drawn, or at least QML/GraphicsView will try to do that.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tipiak
              wrote on last edited by
              #6

              "from the QDeclarativeItem doc":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeitem.html#details

              bq. "Note that, because it does not draw anything, QDeclarativeItem sets the QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual item, you will need to unset this flag."

              It's true for the QGrahpicItem, but as far as i understand this flag is set to true by default for QDeclarativItem.

              .signature

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="Tipiak" date="1300292916"]"from the QDeclarativeItem doc":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeitem.html#details

                bq. "Note that, because it does not draw anything, QDeclarativeItem sets the QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual item, you will need to unset this flag."

                It's true for the QGrahpicItem, but as far as i understand this flag is set to true by default for QDeclarativItem. [/quote]
                Ah, you are right, I stand corrected.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mbrasser
                  wrote on last edited by
                  #8

                  [quote author="bundickt" date="1299870489"]
                  Looking through the qt source it looks like I can override componentComplete if I inherit from QDeclarativeItem, but I am not creating an item that needs to be draw so I inherit from QObject. Is it possible to do this inheriting from QObject or do I have to inherit from QDeclarativeItem, or is there another way of doing this?[/quote]

                  You can do the same thing as QDeclarativeItem for your custom QObject-derived class, you'll just need to inherit "QDeclarativeParserStatus":http://doc.qt.nokia.com/4.7/qdeclarativeparserstatus.html

                  Regards,
                  Michael

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    There is something like QDeclarativeParserStatus which has some methods which might help here.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jsprenkle
                      wrote on last edited by
                      #10

                      The itemchange() method informs you when the parent is set.

                      @RenderWindow::itemChange( ItemChange change, const ItemChangeData& value )
                      {
                      switch ( change )
                      {
                      case QQuickItem::ItemParentHasChanged:
                      // value.item and parent() both contain the new parent
                      }
                      }@

                      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