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. When to use an items id versus the type?
Qt 6.11 is out! See what's new in the release blog

When to use an items id versus the type?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.2k Views 2 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.
  • T Offline
    T Offline
    treaves
    wrote on last edited by
    #1

    I have a ListView whos id is myListView with a delegate. In the delegate code, I set the delegates color based on if it is the current item. Either of these two blocks in the delegate will accomplish this:

    color: ListView.isCurrentItem ? "red" : "black"
    // or
    color:myListView.currentIndex === index ? "red" : "black"
    

    However, this block does not:

    color: myListView.isCurrentItem ? "red" : "black"
    

    Related, I have a click-handler in my delegate to set the ListView's currentIndex property to the delegate's index. This block works:

    myListView.currentIndex = index
    

    whereas this one does not:

    ListView.currentIndex = index
    

    So when are you supposed to refer to something my it's id, and when by it's type? I find this inconsistency problematic.

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      The <Type>.<property> syntax is for attached properties.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        treaves
        wrote on last edited by
        #3

        Thank you very much for clearing that up for me.

        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