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 Taytoo

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

    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on 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
    0
    • SGaistS SGaist

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

      JonBJ 1 Reply Last reply
      0
      • T Taytoo

        @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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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
        0
        • JonBJ JonB

          @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 last edited by
          #13

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

          JonBJ 1 Reply Last reply
          0
          • T Taytoo

            @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;}
            
            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #14

            @Taytoo can you show a picture?

            1 Reply Last reply
            0
            • T Taytoo

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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #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
              0
              • JonBJ JonB

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

                SGaistS 1 Reply Last reply
                0
                • T Taytoo

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

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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
                  1
                  • SGaistS SGaist

                    @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 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
                    • SGaistS SGaist

                      @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 last edited by Taytoo
                      #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
                      0
                      • T Taytoo

                        @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 last edited by Taytoo
                        #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

                        • Login

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