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. Disable highlighting when hovering on QListWidget item?
Forum Updated to NodeBB v4.3 + New Features

Disable highlighting when hovering on QListWidget item?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views 1 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.
  • adalovegirlsA Offline
    adalovegirlsA Offline
    adalovegirls
    wrote on last edited by
    #1

    I'm trying to disable the highlighting of a QListWidget item when hovering over it. I came across two solutions online, as listed here.

    Here's my code to apply the style sheet:

    main.cpp

        app.setStyleSheet("QListWidget::item:hover {background: transparent;}");
        app.setStyleSheet("QListWidget::item:disabled:hover {background: transparent;}");
        app.setStyleSheet("QListWidget::item:hover:!active {background: transparent;}");
    

    I tried the first one, and it works partially but is buggy. In the following screenshots, the right-most of four list widgets has an item in it selected. When I hover over an item in the fourth list widget, the highlighting is still there (as shown in the first screenshot), however, when I hover over one of the other three list widgets, the highlighting is disabled as expected. Additionally, when hovering over another item that is selected (as shown in the second screenshot), the background turns white, instead of staying gray like I want it to (I have all four list widgets set the row to the current row of the item that is clicked in any of the 4 list widgets).


    As for the other method that SGaist suggested, when I try overriding the paint function, I get the error only virtual member functions can be marked 'override'

    debugger.h (click to view full source. Ignore the line being commented)

    #include <QStyledItemDelegate>
    
    protected:
        void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    

    So I couldn't figure out how to override the function as done here. (I did realize that the function in QStyledItemDelegate isn't protected but public, but putting it under public: didn't make a difference.)

    What I want exactly is for no item in the list widgets to have highlighting when hovered over, and the selected row/item to remain gray when both selected and hovered over; I don't what anything to be highlighted blue when selected or hovered over.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @adalovegirls said in Disable highlighting when hovering on QListWidget item?:

      when I try overriding the paint function,

      You have to derive from QStyledItemDelegate, unset State_MouseOver in the paint() function and call the base class impl.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • adalovegirlsA Offline
        adalovegirlsA Offline
        adalovegirls
        wrote on last edited by
        #3

        Thanks. I'll see if I can figure out how to do any of that.

        1 Reply Last reply
        0

        • Login

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