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. Why wrap an inline delegate in a Component?
QtWS25 Last Chance

Why wrap an inline delegate in a Component?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.6k 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.
  • L Offline
    L Offline
    ludde
    wrote on last edited by
    #1

    In some places in the Qt documentation I see constructions like this one (taken from the "QML Scope":http://doc-snapshot.qt-project.org/4.8/qdeclarativescope.html page):

    @
    PathView {
    delegate: Component {
    Rectangle {
    id: root
    Image {
    scale: root.PathView.scale
    }
    }
    }
    }
    @

    My question is, what is the use of the Component element encapsulating the Rectangle element here? Why not use the Rectangle element as delegate directly, i.e.:

    @
    PathView {
    delegate: Rectangle {
    id: root
    Image {
    scale: root.PathView.scale
    }
    }
    }
    @

    Is there any difference between those two approaches, and if so, when should I chose the first and when the second?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      Hello,

      To my humble point of view, since the property delegate itself is a component, there is no difference between the two, (i.e. Component could be almost replaced by Item in the example above).

      dmcr

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MartinJ
        wrote on last edited by
        #3

        As per the previous comment, there is no difference. If the required type is 'Component' but the provided type is not a Component, a Component is created automatically for your convenience. I'd stick with the second just because its nicer to read and less to type.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          ludde
          wrote on last edited by
          #4

          Thanks! I assumed it was something like that, but couldn't quite understand the details. Now I do.

          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