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. Highlight problem for ListView entry when button pressed
QtWS25 Last Chance

Highlight problem for ListView entry when button pressed

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 5.7k 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.
  • Z Offline
    Z Offline
    zibo
    wrote on last edited by
    #1

    Hello.
    I'm new in QLM and I have a problem with some task related to QML ListView. I need to make entries highlighted when pointed by mouse and selected when clicked. Everything works ok untill I press a button on some entry an than move to another - hover doesn't work for other entries. It looks that pressed button blocks other elements (no onEntered, onExited and other signals of those elements). Here is a similar, simplified code (and without selection action for now):

    ListDelegate.qml
    @
    import QtQuick 1.0

    Rectangle {
    id: delegate
    width: ListView.view.width
    height: 40

     Rectangle {
          id: background
          anchors.fill: parent
          color: mArea.containsMouse ? "thistle" : "lightsteelblue"
     }
     Text {
          id: label
          anchors.top: parent.top
          anchors.topMargin: 2
          anchors.left: parent.left
          anchors.leftMargin: 2
          font.family: "Helvetica";
          font.pixelSize: 13;
          font.bold: true
          color: mArea.containsMouse ? "blue" : "red"
          text: name + ":\n\t" + number + "\n"
     }
     MouseArea {
          id: mArea
          anchors.fill: parent
          hoverEnabled: true
     }
    

    }
    @

    ContactModel.qml
    @
    import QtQuick 1.0

    ListModel {
    ListElement {
    name: "Bill Smith"
    number: "555 3264"
    }
    ListElement {
    name: "John Brown"
    number: "555 8426"
    }
    ListElement {
    name: "Sam Wise"
    number: "555 0473"
    }
    }
    @

    main.qml
    @
    import QtQuick 1.0

    Rectangle {
    width: 180; height: 200

     ListView {
          id: list
          width: 180; height: 200
          clip: true
          interactive: false
          model: ContactModel {}
          delegate: ListDelegate {}
          focus: true
     }
    

    }
    @

    Is there any solution (the simpler - the better :) )?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      Are you pressing the mouse button and then moving into another entry with the mouse button still pressed? In Qt (and QML), accepting a mouse press will "grab" all further mouse events until the button is released. In this case that means that the MouseArea you pressed in will get all mouse events (and the MouseAreas in other entries will get none), until the button is released.

      Regards,
      Michael

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zibo
        wrote on last edited by
        #3

        Yes, it is exactly what I am doing. Is there any solution to stop sending all events only to that single MouseArea?

        Thanks

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          I don't know of one unfortunately -- hopefully others can chime in with some possible solutions.

          Regards,
          Michael

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            AFAIK, there is no way to do that directly. The only way I can think of, is to not use a mouse area per item, but a mouse area that overlays the whole list instead. You can then use indexAt to get the indexes from your starting to your end point, so you should be able to calculate which items should be selected from that. The actual selection then needs to be set as a property of the items, I would say, so the delegates can highlight them.

            Note that I did not try to do this myself.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mkcerusky
              wrote on last edited by
              #6

              I am having the same kind of problem, did you or anyone else find a solution to this problem in the meanwhile?

              Thanks in advance

              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