Important: Please read the Qt Code of Conduct -

When to use an items id versus the type?

  • 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.

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

  • Thank you very much for clearing that up for me.

Log in to reply