Custom PushButton



  • Hi
    How can I stop the appearance of a QPushButton changing when it is hovered over or pressed.
    I know how to change the background colour for these events by setting the appropriate stylesheet, but cannot see how I can stop them changing at all.
    I would appreciate some help in getting this working

    Thanks



  • Hi,

    Try with the :event syntax

    Example :
    QPushButton:hover { color: white }

    Good luck!


  • Moderators

    [quote author="GrahamL" date="1385052636"]
    I know how to change the background colour for these events by setting the appropriate stylesheet, but cannot see how I can stop them changing at all.[/quote]
    You mean that a hovered button looks exactly the same like a non-hovered button?
    If thats the case you can do this:
    @
    void MyPushButton::paintEvent(QPaintEvent *)
    {
    QStylePainter p(this);
    QStyleOptionButton option;
    initStyleOption(&option);
    option.state &= ~QStyle::State_MouseOver; //remove hover flag in all cases ("~" is supposed to be a tilde-sign)
    p.drawControl(QStyle::CE_PushButton, option);
    }
    @


Log in to reply
 

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