Stylesheet for making a button flat?



  • I need a button that looks exactly like a QToolButton with autoRaise=true. However, QToolButton has a problem: after being highlighted when hovered, it often wouldn't lose highlight as mouse cursor moves off (tested and confirmed on Windows 7 and Linux with KDE).

    So, I'm wondering if it's possible to make a regular button (either QPushButton or QToolButton) flat by means of a QSS stylesheet.


  • Moderators

    [quote author="Violet Giraffe" date="1403422120"]QToolButton has a problem: after being highlighted when hovered, it often wouldn't lose highlight as mouse cursor moves off (tested and confirmed on Windows 7 and Linux with KDE).[/quote]
    Is that a known bug? I can't seem to reproduce it. Which compiler and Qt version are you using?

    [quote author="Violet Giraffe" date="1403422120"]So, I'm wondering if it's possible to make a regular button (either QPushButton or QToolButton) flat by means of a QSS stylesheet.[/quote]
    Not entirely, no.
    You can make the button borderless and transparent and give it some highlight on hover:
    @
    QPushButton {
    border: none;
    background: transparent;
    }

    QPushButton:hover {
    border: 1px solid blue;
    background: red;
    }
    @
    but the colors will be fixed and no system style(gradients, animation etc) will be applied. You can use "palette(button)" etc. as colors to make it closer to system look but it won't look 100% native.



  • [quote author="Chris Kawa" date="1403433300"]
    Is that a known bug?[/quote]
    No idea. Visual Studio 2012 and gcc 4.8.2 (not that it could be caused by a compiler), Qt 5.3 final on both systems.

    The bug is more complicated than I've initially described. It happens when button click opens QMenu. Then, if you click anywhere on the window to close the menu, the button will become highlighted until you hover it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.