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. QListWidget disable hover for item widget?
Forum Updated to NodeBB v4.3 + New Features

QListWidget disable hover for item widget?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 2.0k Views 2 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.
  • T Offline
    T Offline
    Taytoo
    wrote on 5 May 2023, 12:38 last edited by Taytoo 5 May 2023, 12:39
    #1

    I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?

    I've tried using stylesheet as proposed in other solutions but that doesn't work.

    S J 2 Replies Last reply 5 May 2023, 19:21
    0
    • T Taytoo
      9 May 2023, 05:56

      @SGaist said in QListWidget disable hover for item widget?:

      @Taytoo your original stylesheet does not apply to items of an item view.
      Try something like:

      QListWidget::item:hover,
      QListWidget::item:disabled:hover,
      QListWidget::item:hover:!active,
      {background: transparent;}
      

      Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
      I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work.

      T Offline
      T Offline
      Taytoo
      wrote on 9 May 2023, 06:14 last edited by Taytoo 5 Sept 2023, 09:20
      #20

      Finally, found a solution! The trick is Not to use hover modifier/attribute for disabled items

      QListWidget::item:disabled,
      QListWidget::item:!active,
      {background: transparent;}
      

      This stylesheet plus removing IsEnabled or IsSelectable flag for desired items will disable hover effect.

      1 Reply Last reply
      0
      • T Taytoo
        5 May 2023, 12:38

        I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?

        I've tried using stylesheet as proposed in other solutions but that doesn't work.

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 5 May 2023, 19:21 last edited by
        #2

        Hi,

        What exactly are you trying to do with your list widget ? As noted in the documentation and many posts on this forum, it should not be used beside showing some static content. If you need one widget per element then you should rather implement a custom QStyledItemDelegate.

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

        T 1 Reply Last reply 6 May 2023, 15:07
        0
        • T Taytoo
          5 May 2023, 12:38

          I'm using setItemWidget to set a widget for each item added to QListWidget. How do I disable hover effect for specific items/itemwidgets?

          I've tried using stylesheet as proposed in other solutions but that doesn't work.

          J Offline
          J Offline
          JoeCFD
          wrote on 5 May 2023, 21:10 last edited by JoeCFD 5 May 2023, 21:11
          #3

          @Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?

          T 1 Reply Last reply 6 May 2023, 15:08
          0
          • S SGaist
            5 May 2023, 19:21

            Hi,

            What exactly are you trying to do with your list widget ? As noted in the documentation and many posts on this forum, it should not be used beside showing some static content. If you need one widget per element then you should rather implement a custom QStyledItemDelegate.

            T Offline
            T Offline
            Taytoo
            wrote on 6 May 2023, 15:07 last edited by
            #4

            @SGaist said in QListWidget disable hover for item widget?:

            Hi,

            What exactly are you trying to do with your list widget ?

            It will be used to show static content, typically around 5 items. I'm using setItemWidget since its much simpler than QStyledItemDelegate.
            Only issue is that I'm insert a dummy item/widget for visual separation of certain items but when mouse moves over the dummy item/widget, there is hover (blue background) effect on that as well and I'd like to disable it.

            1 Reply Last reply
            0
            • J JoeCFD
              5 May 2023, 21:10

              @Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?

              T Offline
              T Offline
              Taytoo
              wrote on 6 May 2023, 15:08 last edited by
              #5

              @JoeCFD said in QListWidget disable hover for item widget?:

              @Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?

              I tried following in stylesheet but didn't work:

              QWidget::hover,
              QWidget::disabled:hover,
              QWidget::hover:!active,
              {background: transparent;}
              
              J J 2 Replies Last reply 6 May 2023, 15:45
              0
              • T Taytoo
                6 May 2023, 15:08

                @JoeCFD said in QListWidget disable hover for item widget?:

                @Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?

                I tried following in stylesheet but didn't work:

                QWidget::hover,
                QWidget::disabled:hover,
                QWidget::hover:!active,
                {background: transparent;}
                
                J Offline
                J Offline
                JonB
                wrote on 6 May 2023, 15:45 last edited by JonB 5 Jun 2023, 15:45
                #6

                @Taytoo
                Just a thought: is that "blue background" a hover for the cell/table, not the widget? Does your "empty" QWidget fill the cell? Because if it is "tiny" with no content maybe what you are seeing is cell background? I don't know.

                T 1 Reply Last reply 6 May 2023, 18:47
                0
                • J JonB
                  6 May 2023, 15:45

                  @Taytoo
                  Just a thought: is that "blue background" a hover for the cell/table, not the widget? Does your "empty" QWidget fill the cell? Because if it is "tiny" with no content maybe what you are seeing is cell background? I don't know.

                  T Offline
                  T Offline
                  Taytoo
                  wrote on 6 May 2023, 18:47 last edited by
                  #7

                  @JonB Widget is as wide as QListWidget, but the QLabel is centered inside it (not stretched to edges of Widget).

                  S 1 Reply Last reply 6 May 2023, 19:13
                  0
                  • T Taytoo
                    6 May 2023, 18:47

                    @JonB Widget is as wide as QListWidget, but the QLabel is centered inside it (not stretched to edges of Widget).

                    S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 6 May 2023, 19:13 last edited by
                    #8

                    @Taytoo what are you showing ? Text ? Images ?

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

                    T 1 Reply Last reply 6 May 2023, 20:17
                    0
                    • S SGaist
                      6 May 2023, 19:13

                      @Taytoo what are you showing ? Text ? Images ?

                      T Offline
                      T Offline
                      Taytoo
                      wrote on 6 May 2023, 20:17 last edited by
                      #9

                      @SGaist Just text inside QLabel but the parent QWidget just has default background

                      S 1 Reply Last reply 7 May 2023, 19:08
                      0
                      • T Taytoo
                        6 May 2023, 20:17

                        @SGaist Just text inside QLabel but the parent QWidget just has default background

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 7 May 2023, 19:08 last edited by
                        #10

                        If it's just a background issue, just set the corresponding role in your model. It will simplify everything.

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

                        T 1 Reply Last reply 8 May 2023, 05:25
                        0
                        • S SGaist
                          7 May 2023, 19:08

                          If it's just a background issue, just set the corresponding role in your model. It will simplify everything.

                          T Offline
                          T Offline
                          Taytoo
                          wrote on 8 May 2023, 05:25 last edited by
                          #11

                          @SGaist What do you mean by set the corresponding role? I'm just adding items to QListWidget, not using Model/View like you have to with QListView

                          J 1 Reply Last reply 8 May 2023, 07:37
                          0
                          • T Taytoo
                            8 May 2023, 05:25

                            @SGaist What do you mean by set the corresponding role? I'm just adding items to QListWidget, not using Model/View like you have to with QListView

                            J Offline
                            J Offline
                            JonB
                            wrote on 8 May 2023, 07:37 last edited by
                            #12

                            @Taytoo

                            • For a QListWidget any QListWidgetItem can call void QListWidgetItem::setBackground(const QBrush &brush).
                            • Or listWidget->model()->setData(index, brush, Qt::BackgroundRole) should do it.
                            • Or you could interpose a QAbstractProxyModel between the QListWidget and its supplied model(), where your proxy model overrides data() method to return the brush for the Qt::BackgroundRole role.

                            For the brush I think you can use QBrush(Qt::transparent) or perhaps plain Qt::transparent.

                            T 1 Reply Last reply 8 May 2023, 15:19
                            0
                            • J JonB
                              8 May 2023, 07:37

                              @Taytoo

                              • For a QListWidget any QListWidgetItem can call void QListWidgetItem::setBackground(const QBrush &brush).
                              • Or listWidget->model()->setData(index, brush, Qt::BackgroundRole) should do it.
                              • Or you could interpose a QAbstractProxyModel between the QListWidget and its supplied model(), where your proxy model overrides data() method to return the brush for the Qt::BackgroundRole role.

                              For the brush I think you can use QBrush(Qt::transparent) or perhaps plain Qt::transparent.

                              T Offline
                              T Offline
                              Taytoo
                              wrote on 8 May 2023, 15:19 last edited by
                              #13

                              @JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?

                              J 1 Reply Last reply 8 May 2023, 15:55
                              0
                              • T Taytoo
                                6 May 2023, 15:08

                                @JoeCFD said in QListWidget disable hover for item widget?:

                                @Taytoo I guess the widget is on top of QListWidget item. Can you try to disable hovering for that widget(not list item) with style sheet since list item is empty(nullptr) in the cell of widget?

                                I tried following in stylesheet but didn't work:

                                QWidget::hover,
                                QWidget::disabled:hover,
                                QWidget::hover:!active,
                                {background: transparent;}
                                
                                J Offline
                                J Offline
                                JoeCFD
                                wrote on 8 May 2023, 15:37 last edited by
                                #14

                                @Taytoo can you show a picture?

                                1 Reply Last reply
                                0
                                • T Taytoo
                                  8 May 2023, 15:19

                                  @JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 8 May 2023, 15:55 last edited by JonB 5 Aug 2023, 15:55
                                  #15

                                  @Taytoo said in QListWidget disable hover for item widget?:

                                  @JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?

                                  I was just (hopefully, unless I got it wrong) fleshing out:
                                  @SGaist said in QListWidget disable hover for item widget?:

                                  If it's just a background issue, just set the corresponding role in your model. It will simplify everything.

                                  when you asked

                                  @SGaist What do you mean by set the corresponding role?

                                  Perhaps he will explain if that simplifies things :)

                                  T 1 Reply Last reply 8 May 2023, 15:59
                                  0
                                  • J JonB
                                    8 May 2023, 15:55

                                    @Taytoo said in QListWidget disable hover for item widget?:

                                    @JonB I'm a bit confused, how would setting the background brush disable Hover effect on QListWidget item widget?

                                    I was just (hopefully, unless I got it wrong) fleshing out:
                                    @SGaist said in QListWidget disable hover for item widget?:

                                    If it's just a background issue, just set the corresponding role in your model. It will simplify everything.

                                    when you asked

                                    @SGaist What do you mean by set the corresponding role?

                                    Perhaps he will explain if that simplifies things :)

                                    T Offline
                                    T Offline
                                    Taytoo
                                    wrote on 8 May 2023, 15:59 last edited by
                                    #16

                                    @JonB Tried setting Background brush on Item. It has no effect on hover. If I change the background to Red, then item background is colored Red, but moving mouse over the widget still shows the hover effect (bluish color).

                                    I'm starting to think maybe its a Qt bug or Qt on Windows 10 issue, because the suggested stylesheet fixes aren't working at all.

                                    S 1 Reply Last reply 8 May 2023, 18:36
                                    0
                                    • T Taytoo
                                      8 May 2023, 15:59

                                      @JonB Tried setting Background brush on Item. It has no effect on hover. If I change the background to Red, then item background is colored Red, but moving mouse over the widget still shows the hover effect (bluish color).

                                      I'm starting to think maybe its a Qt bug or Qt on Windows 10 issue, because the suggested stylesheet fixes aren't working at all.

                                      S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 8 May 2023, 18:36 last edited by
                                      #17

                                      @Taytoo your original stylesheet does not apply to items of an item view.
                                      Try something like:

                                      QListWidget::item:hover,
                                      QListWidget::item:disabled:hover,
                                      QListWidget::item:hover:!active,
                                      {background: transparent;}
                                      

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

                                      T 2 Replies Last reply 8 May 2023, 20:29
                                      1
                                      • S SGaist
                                        8 May 2023, 18:36

                                        @Taytoo your original stylesheet does not apply to items of an item view.
                                        Try something like:

                                        QListWidget::item:hover,
                                        QListWidget::item:disabled:hover,
                                        QListWidget::item:hover:!active,
                                        {background: transparent;}
                                        
                                        T Offline
                                        T Offline
                                        Taytoo
                                        wrote on 8 May 2023, 20:29 last edited by
                                        #18

                                        @SGaist I'm able to get hover effect to work if I remove the disabled modifier in stylesheet. But if an Item is disabled using code below (hoping this is correct way of disabling an item?), then the stylesheet doesn't work.

                                        item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
                                        
                                        1 Reply Last reply
                                        0
                                        • S SGaist
                                          8 May 2023, 18:36

                                          @Taytoo your original stylesheet does not apply to items of an item view.
                                          Try something like:

                                          QListWidget::item:hover,
                                          QListWidget::item:disabled:hover,
                                          QListWidget::item:hover:!active,
                                          {background: transparent;}
                                          
                                          T Offline
                                          T Offline
                                          Taytoo
                                          wrote on 9 May 2023, 05:56 last edited by Taytoo 5 Sept 2023, 05:57
                                          #19

                                          @SGaist said in QListWidget disable hover for item widget?:

                                          @Taytoo your original stylesheet does not apply to items of an item view.
                                          Try something like:

                                          QListWidget::item:hover,
                                          QListWidget::item:disabled:hover,
                                          QListWidget::item:hover:!active,
                                          {background: transparent;}
                                          

                                          Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
                                          I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work.

                                          T 1 Reply Last reply 9 May 2023, 06:14
                                          0
                                          • T Taytoo
                                            9 May 2023, 05:56

                                            @SGaist said in QListWidget disable hover for item widget?:

                                            @Taytoo your original stylesheet does not apply to items of an item view.
                                            Try something like:

                                            QListWidget::item:hover,
                                            QListWidget::item:disabled:hover,
                                            QListWidget::item:hover:!active,
                                            {background: transparent;}
                                            

                                            Experimented a bit using this stylesheet. It works Only on Enabled items. If I remove IsSelectable flag or IsEnabled flag, then the stylesheet doesn't work and normal hover effect is shown.
                                            I've even tried disabling the widget that I'm setting for the item using setItemWidget, still didn't work.

                                            T Offline
                                            T Offline
                                            Taytoo
                                            wrote on 9 May 2023, 06:14 last edited by Taytoo 5 Sept 2023, 09:20
                                            #20

                                            Finally, found a solution! The trick is Not to use hover modifier/attribute for disabled items

                                            QListWidget::item:disabled,
                                            QListWidget::item:!active,
                                            {background: transparent;}
                                            

                                            This stylesheet plus removing IsEnabled or IsSelectable flag for desired items will disable hover effect.

                                            1 Reply Last reply
                                            0
                                            • T Taytoo has marked this topic as solved on 9 May 2023, 06:14

                                            6/20

                                            6 May 2023, 15:45

                                            14 unread
                                            • Login

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