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.
  • 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

                      20/20

                      9 May 2023, 06:14

                      • Login

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