Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to remove QPushButton border but keep effect



  • I'm trying to recreate the Float and Close button from the QDockWidget default title bar, they look like this:
    979fe779-45c0-4fd8-868e-bbc2f2c0b84e-image.png

    I have figured out so far how to get that icon and as far:

    auto icon = style()->standardIcon(QStyle::SP_TitleBarNormalButton, nullptr, this);
    

    As I can see the icon has the three states that I require, normal, hover and pressed. Added to a QPushButton it looks as expected. Now I have removed the border by changing the StyleSheet:

    button->setStyleSheet("QPushButton {border-style: outset; border-width: 0px;}");
    

    The button looks now exactly as I need it to look but the problem is that there is no hover effect and if I click on the button it changes the icon to the pressed state as expected but when I release it, it stays in that state. Interesting is that when I click on the that same button of another dock widget, the first button goes back to normal state and the second button stays in the pressed state. Any idea what might be going wrong or what an alternative could be?


  • Lifetime Qt Champion

    Hi
    When you apply a stylesheet, the normal drawing is no longer in effect.
    So you have to style it fully.
    For hover, you might want to use ":hover" key to assign an effect.

    For the stay down, Im a bit baffled.
    It really sounds like it's flagged as checkable and shares a button group with the other instances.
    But Not sure where that would come from.
    You set a custom widget to title bar ?



  • Yes, it was a custom widget in title bar. I wasn't able to figure out where this is coming from so I went with a different solution but still strange behavior.