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
Forum Updated to NodeBB v4.3 + New Features

how to set hightlight color to qml listview item

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 714 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on 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
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on 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
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on 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.

        JoeCFDJ 1 Reply Last reply
        1
        • fcarneyF fcarney

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

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @fcarney This works too. Thanks.

          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