Qt QPushButton table style

I have the following button stylesheet:

QPushButton:hover{
        background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 :   1, stop :   0.0 #ffd9aa,
                stop :   0.5 #ffbb6e, stop :   0.55 #feae42, stop :   1.0 #fedb74);
}

QPushButton {
        border: 1px solid #6593cf;
        border-radius: 2px;
        padding: 5px 15px 2px 5px;
        background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 :   1, stop :   0.0 #f5f9ff,
                stop :   0.5 #c7dfff, stop :   0.55 #afd2ff, stop :   1.0 #c0dbff);
        color: #006aff;
        font: bold large "Arial";
        height: 30px;
}




QPushButton:pressed {
        background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 :   1, stop :   0.0 #c0dbff,
        stop :   0.5 #cfd26f, stop :   0.55 #c7df6f, stop :   1.0 #f5f9ff);
        padding-top: 2px;
        padding-left: 3px;

}


QPushButton:on {
        background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 :   1, stop :   0.0 #5AA72D,
        stop :   0.5 #B3E296, stop :   0.55 #B3E296, stop :   1.0 #f5f9ff);
        padding-top: 2px;
        padding-left: 3px;
}

QPushButton:disabled {
        background: transparent #e5e9ee;
        padding-top: 2px;        
        padding-left: 3px;
        color: black;
}

      

I have a button. When pressed, the side widget changes. This way the button gets the style pressed, when I release it the hover style appears. In addition, the widget changes and the button "follows" the widget. The problem is that the button retains the hover state and loses it when I move with the mouse. Is this a bug from qt or am I missing something in the stylesheet code.

I made an animated gif showing the situation: enter image description here

thank

+3


source to share


1 answer


You can tell that this is a bug in Qt. I would say that these are some kind of errors caused by correct logic. Judge for yourself. The state is Hover

determined by the attribute of the widget WA_UnderMouse

. This attribute is set by the application:

if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) ...
        widget->setAttribute(Qt::WA_UnderMouse, true);
else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
        widget->setAttribute(Qt::WA_UnderMouse, false);

      



QEvent::Enter

and QEvent::Leave

events are dispatched only when the application receives a mouse event from the OS.
You don't move the mouse, the application doesn't receive any mouse event, so the attribute WA_UnderMouse

doesn't change.
One way to fix this is to set the attribute Qt::WA_UnderMouse

to the correct value yourself when you move the button widget.

+5


source







All Articles