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 is there extra wrapping of components?
Qt 6.11 is out! See what's new in the release blog

Why is there extra wrapping of components?

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 515 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.
  • C Offline
    C Offline
    cscooper
    wrote on last edited by
    #1

    I see this a lot in online code - somebody needs a checkbox in a table, and they define their delegate like "matryoshkas":http://en.wikipedia.org/wiki/Matryoshka_doll:
    @Component {
    id: checkBoxDelegate

    Item {
        CheckBox {
            anchors.fill: parent
            checked: styleData.value
        }
    }
    

    }
    @

    What is the benefit of this over a more simple definition:
    @CheckBox {
    id: checkBoxDelegate
    anchors.fill: parent
    checked: styleData.value
    }
    @

    And it's not just people in the interwebs, the Qt documentation does the same thing (in http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html )

    @
    itemDelegate: Item {
    Text {
    anchors.verticalCenter: parent.verticalCenter
    color: styleData.textColor
    elide: styleData.elideMode
    text: styleData.value
    }
    }
    @

    Why the extra layer of "Item" there? Why not just:

    @
    itemDelegate: Text {
    anchors.verticalCenter: parent.verticalCenter
    color: styleData.textColor
    elide: styleData.elideMode
    text: styleData.value
    }
    @

    Thanks,
    Chris

    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