Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Item stuck in mouseover state when the mouse leaves a QListView
QtWS25 Last Chance

Item stuck in mouseover state when the mouse leaves a QListView

Scheduled Pinned Locked Moved Solved General and Desktop
qlistviewqstyleditemdele
6 Posts 3 Posters 2.2k 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.
  • P Offline
    P Offline
    plover
    wrote on 29 May 2018, 09:18 last edited by plover
    #1

    Hi I posted this question on stackoverflow with no response so I'm going to try here.

    When the mouse cursors leaves a QListview, the last item that the mouse was over is sometimes still stuck in mouse over state. This usually happens if I move the mouse to the parent widget or another QListview that is above it.

    My QListView has a QStyledItemDelegate that draws the item and I check the mouse over state in the paint method in the following way :

    void MyDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
    {
        if( option.state & QStyle::State_MouseOver)
         {
            // Paint in MouseOver state
         }
         else
         {
            // Paint normally
         }
     }
    

    Then I implemented the leaveEvent in my QListView to call update so the view is updated when the mouse leave the view.

    void MyListView::leaveEvent(QEvent *event)
    {
       update();
       QListView::leaveEvent(event);
    }
    

    This does call the paint method of the delegate on leave but doesn't change the hover state of the item last hovered over in the QListView.

    Is there a way to force the delegate to repaint and the last item not be in mouse over state when the cursor leaves the listview ?

    J 1 Reply Last reply 29 May 2018, 09:42
    0
    • P plover
      29 May 2018, 09:18

      Hi I posted this question on stackoverflow with no response so I'm going to try here.

      When the mouse cursors leaves a QListview, the last item that the mouse was over is sometimes still stuck in mouse over state. This usually happens if I move the mouse to the parent widget or another QListview that is above it.

      My QListView has a QStyledItemDelegate that draws the item and I check the mouse over state in the paint method in the following way :

      void MyDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
      {
          if( option.state & QStyle::State_MouseOver)
           {
              // Paint in MouseOver state
           }
           else
           {
              // Paint normally
           }
       }
      

      Then I implemented the leaveEvent in my QListView to call update so the view is updated when the mouse leave the view.

      void MyListView::leaveEvent(QEvent *event)
      {
         update();
         QListView::leaveEvent(event);
      }
      

      This does call the paint method of the delegate on leave but doesn't change the hover state of the item last hovered over in the QListView.

      Is there a way to force the delegate to repaint and the last item not be in mouse over state when the cursor leaves the listview ?

      J Offline
      J Offline
      JonB
      wrote on 29 May 2018, 09:42 last edited by
      #2

      @plover
      Is it worth a try to see whether it works right if in your override you call the base leaveEvent() before the update()`?

      1 Reply Last reply
      1
      • P Offline
        P Offline
        plover
        wrote on 29 May 2018, 09:47 last edited by plover
        #3

        I've already tried that. I've also tried to delay the update() by using a QTimer but the results are the same.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 May 2018, 21:17 last edited by
          #4

          Hi,

          You should also tell:

          • Which version of Qt
          • Which OS

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply 30 May 2018, 09:01
          1
          • S SGaist
            29 May 2018, 21:17

            Hi,

            You should also tell:

            • Which version of Qt
            • Which OS
            P Offline
            P Offline
            plover
            wrote on 30 May 2018, 09:01 last edited by plover
            #5

            @SGaist
            I'm currently using Qt 5.6, and I've tested this on centos 7, fedora 27 and 28.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              plover
              wrote on 30 May 2018, 13:59 last edited by
              #6

              I updated the QT version to 5.11 and the problem goes away. No need to implement the leaveEvent of the QListView.
              Tested also with 5.10 and it worked there as well.

              1 Reply Last reply
              2

              2/6

              29 May 2018, 09:42

              topic:navigator.unread, 4
              • Login

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