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. Could highlight object in Listview/Gridview be changed while running?
Forum Updated to NodeBB v4.3 + New Features

Could highlight object in Listview/Gridview be changed while running?

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

    As title describing?
    Thank you.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cokefish
      wrote on last edited by
      #2

      I means that Could a highlight hold State inside?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        daliusd
        wrote on last edited by
        #3

        Not really. Highlight requires Component (http://doc.qt.digia.com/qt/qml-component.html) and only elements that inherit from Qml Item can have state (http://doc.qt.digia.com/qt/qml-item.html).

        I guess you want to have different highlight bar based on some condition. That basically means you should use different highlight based on list state (example below that changes highlight component based on current item. It is without states but should be easy rewrite to use states).

        As side note: I personally don't use highlight at all. There might be good reasons to use it but I have found that it gives me more problems than solves. isCurrentItem is enough for me.

        @import QtQuick 1.1

        Rectangle {
        width: 180; height: 200

        ListModel {
            id: contactsModel
            ListElement {
                name: "Bill Smith"
                number: "555 3264"
            }
            ListElement {
                name: "John Brown"
                number: "555 8426"
            }
            ListElement {
                name: "Sam Wise"
                number: "555 0473"
            }
        }
        
        Component {
            id: contactDelegate
            Item {
                width: 180; height: 40
                Column {
                    Text { text: '<b>Name:</b> ' + name }
                    Text { text: '<b>Number:</b> ' + number }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        myList.currentIndex = index
                        myList.highlight = index % 2 == 0 ? highlightBar : highlightBar2;
                    }
                }
            }
        }
        
        Component {
                 id: highlightBar
        
                 Rectangle {
                     color: "blue"
                 }
             }
        
        Component {
                 id: highlightBar2
        
                 Rectangle {
                     color: "red"
                 }
             }
        
        ListView {
            id: myList
            anchors.fill: parent
            model: contactsModel
            delegate: contactDelegate
            highlight: highlightBar
            focus: true
        }
        

        }
        @

        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