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. Determining properties of an item in a ListView given other items in the ListView
Forum Updated to NodeBB v4.3 + New Features

Determining properties of an item in a ListView given other items in the ListView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 122 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.
  • A Offline
    A Offline
    A.Sime
    wrote on last edited by
    #1

    Hi there,
    Currently I am trying to implement highlighting for items in a ListView, where I place a border around each item, and remove the border between adjacent items.
    I've created a component for highlighting, where I can control whether I want a top, bottom, left and right border for each item, but I am unable to set these borders according to the next/previous item in the list.
    The example below is a basic rundown:

    ListView {
    model: myModel
    
     delegate: Item {
      property bool isChecked: false
    
      HighlightComponent {
       topBorderWidth: [read previous items isChecked property] ? 0 : 1
       bottomBorderWidth: [read next items isChecked property] ? 0 : 1
      }
     }
    }
    
    

    Any advice is much appreciated,
    Thanks!

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      I think you will have to use https://doc.qt.io/qt-5/qml-qtquick-listview.html#itemAtIndex-method to get the Item before and after the current item. I think if it is not rendered it may return null. But if that is the case it should be off screen.

      let beforeitem = <listviewid>.itemAtIndex(index-1)
      let afteritem = <listviewid>.itemAtIndex(index+1)
      

      Probably need to do check with isChecked to trigger changes. Might need to be tricky and fire off events or create a signal that fires anytime any isChecked changes. You can use Qt.callLater to make sure the event is not called for every item all the time.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved