Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QListWidget: How to disable when mouse hover ,the items change background color?

    General and Desktop
    qlistwidget hover
    4
    8
    8512
    Loading More Posts
    • 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.
    • brucezcg
      brucezcg last edited by

      For QListWidget
      By Default when mouse hover ,the list items will change background color.
      How to disable this feature?
      I want the item do nothing when mouse hover the list items.

      Thanks

      A 1 Reply Last reply Reply Quote 0
      • A
        ambershark @brucezcg last edited by

        @brucezcg Here's 2 different ways to do it.. One with CSS (the easy way) and the other with a custom paint (the hard way).

        https://stackoverflow.com/questions/16016644/deactivated-qlistwidgetitem-hover

        https://stackoverflow.com/questions/42403175/qlistwidget-disable-mouseover-highlight

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply Reply Quote 1
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Two solutions comes to mind:

          • QStyledItemDelegate
          • Qt Style Sheet

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

          1 Reply Last reply Reply Quote 2
          • brucezcg
            brucezcg last edited by

            I don't want to change background color when hover,
            I just want to disable hover, when hover, the items stay the background color, may be different colors, so I couldn't set
            hover to certain color.

            D A 2 Replies Last reply Reply Quote 0
            • D
              Devopia53 @brucezcg last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Then QStyledItemDelegate it is.

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

                brucezcg 1 Reply Last reply Reply Quote 0
                • brucezcg
                  brucezcg @SGaist last edited by

                  @ambershark @SGaist Get it, Thanks.

                  1 Reply Last reply Reply Quote 0
                  • A
                    ambershark @brucezcg last edited by

                    @brucezcg said in QListWidget: How to disable when mouse hover ,the items change background color?:

                    I don't want to change background color when hover,
                    I just want to disable hover, when hover, the items stay the background color, may be different colors, so I couldn't set
                    hover to certain color.

                    Well in that post I linked you on stackoverflow, it shows:

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

                    That means it just hides the hover, doesn't set it to a certain color. It should do exactly what you need.

                    You can of course make a custom delegate too. That's more work that setting a quick css though.

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post