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. [SOLVED]QML listview highlight problem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QML listview highlight problem

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 5.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.
  • G Offline
    G Offline
    gedixss
    wrote on 22 Apr 2014, 14:44 last edited by
    #1

    Hi,

    I have a problem with listview and highlight component. For now my highlight component is after the listview component, like in this picture:
    !http://i.imgur.com/yvfWy53.png(highlight after listview)!
    I want to do like this:
    !http://i.imgur.com/IUaMaW2.png(Good example)!

    My listview:

    @Rectangle {
    id: _scrollbar_area;
    width: 1100;
    height: 520;
    x: 50;
    clip:true;
    anchors.verticalCenter: parent.verticalCenter;
    color: "transparent"
    radius: 8;
    ListView {
    id: list;
    anchors.horizontalCenter: parent.horizontalCenter;
    anchors.verticalCenter: parent.verticalCenter;
    anchors.fill: parent;
    delegate: component;
    highlight: highlightBar;
    highlightFollowsCurrentItem: false;
    focus: true;
    model: 10;
    }
    }@

    Highlight component:

    @Component {
    id: highlightBar
    Rectangle {
    width: 1100; height: 60
    y: list.currentItem.y;
    radius: 8;
    opacity: 1;
    gradient: onn;
    Gradient {
    id:onn
    GradientStop { position: 0.0; color: "#01bd5e" }
    GradientStop { position: 1.0; color: "#006a10" }
    }
    Behavior on y { SpringAnimation { spring: 10; damping: 1 } }
    }
    }@

    listview component:

    @Component {
    id:component;
    Row {
    spacing: 15
    height: 77;
    width: parent.width;
    Rectangle {
    id: list_item;
    signal clicked();
    height: 57;
    width: parent.width;
    radius: 8;
    color: "#c2c2c2"

                Text {
                    id: rules;
                    y: 25;
                    anchors.left: parent.left;
                    anchors.leftMargin: 20;
                    anchors.verticalCenter: parent.verticalCenter;
                    text: "Text";
                    font.pixelSize: 20;
                    font.family: font_.name;
                    opacity: 1;
                }
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        list_item.clicked();
                        list.currentIndex = index;
                        list_item.color = "transparent";
                    }
                }
            }
        }
    }@
    

    I tried change the listview component color to transparent, but when i clicked another listview elements all clicked elements goes transparent, i want that listview elements goes back to "#c2c2c2" color. Sorry for my english ;))

    Thanks in advance ;)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on 22 Apr 2014, 20:23 last edited by
      #2

      You can check for isCurrentItem in your delegate, and make your background transparent. And apply the green gradient to your highlight item....

      @
      Rectangle {
      id: list_item;
      signal clicked();
      height: 57;
      width: parent.width;
      radius: 8;
      color: _scrollbar_area.isCurrentIem ? "transparent" : "#c2c2c2"
      }
      @

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gedixss
        wrote on 23 Apr 2014, 06:26 last edited by
        #3

        I tried with it, but when i clicked my listview item nothing happend... what i'm doing wrong, any more ideas ?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gedixss
          wrote on 23 Apr 2014, 08:32 last edited by
          #4

          I solved it, mistake was in my delegate.

          Code:

          @Rectangle {
          id: _scrollbar_area;
          ...
          ListView {
          id: list;
          ...
          delegate: Item {
          id:component;
          height: 72;
          width: parent.width;
          Row {
          height: 77;
          width: parent.width;
          Rectangle {
          id: list_item;
          signal clicked();
          height: 57;
          width: parent.width;
          radius: 8;
          color : component.ListView.isCurrentItem ? "transparent" : "#c2c2c2"
          Text {
          ...
          }

                             MouseArea {
                                 anchors.fill: parent
                                 onClicked: {
                                     list_item.clicked();
                                     list.currentIndex = index;
                                 }
                             }
                         }
                     }
                 }
                 highlight: highlightBar;
                 highlightFollowsCurrentItem: false;
                 focus: true;
                 model: 10;
              }
          }@
          
          1 Reply Last reply
          0

          1/4

          22 Apr 2014, 14:44

          • Login

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