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. how to set hightlight color to qml listview item

how to set hightlight color to qml listview item

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 674 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.
  • J Offline
    J Offline
    JoeCFD
    wrote on 20 Jun 2022, 00:39 last edited by JoeCFD
    #1

    new to qml. I set alternative colors to items inside qml listview. But the highlight color "lightsteelblue" does not show up. What is wrong?

        ListView {
            id: nameListView
            anchors.fill: parent
            snapMode: ListView.SnapToItem
            spacing: 0
            focus: true
            interactive: false
            model: nameListModel
    
            property int selectedRow: 1
    
            delegate: Rectangle {
                id: infoDelegate
                width: nameListView.width
                height: menubar.height * 0.8
                color: index % 2 == 0 ? "lightgray" : "black"
    
                Text {
                    anchors.centerIn: parent
                    font.pixelSize: 24
                    text: itemTime
                    color: "white"
                }
    
                MouseArea {
                    anchors.fill: infoDelegate
                    onClicked: {
                        nameListView.selectedRow = index
                    }
                }
            }
    
            highlight: Rectangle {
                color: "lightsteelblue"
            }
        }
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 20 Jun 2022, 15:00 last edited by JoeCFD
      #2

      I have to set the background color of delegate to be transparent since delegate is on top of the highlight color. But more code is needed to reset everything.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcarney
        wrote on 20 Jun 2022, 15:03 last edited by
        #3

        You can set z on your highlight to something like 5. This should raise it above the delegate.

        C++ is a perfectly valid school of magic.

        J 1 Reply Last reply 20 Jun 2022, 16:12
        1
        • F fcarney
          20 Jun 2022, 15:03

          You can set z on your highlight to something like 5. This should raise it above the delegate.

          J Offline
          J Offline
          JoeCFD
          wrote on 20 Jun 2022, 16:12 last edited by
          #4

          @fcarney This works too. Thanks.

          1 Reply Last reply
          0

          4/4

          20 Jun 2022, 16:12

          • Login

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