Refresh GUI / Stylesheet [Button Mouse Hover fail when showing popup in Click Function]
-
Hi,
I just experienced a very wierd behaviour.
I have a Button. There's a Stylesheet connected to the button. (Mouse Hover)
When i click the Button a QWidget Popup appears.
But the Button got stuck in mouse Hover State (Changed Backcolor). Even when the Pop-Up closes, the Button stays in Mouse Hover State even when the mouse is not even on the window. Only if i move back the mouse to the button again and leave, the button changes back to its origin back-color (as it should).By now i know i could make a subclass of QMenu to accomplish my goal but I've already done the complete implementation. So my Question is how to refresh the gui or force the button to check the mouse hover?
-
basically call update() on the button.
But show us some code i think there may be something wrong.
-
also the update wont do it.
Here's the Code:
Private Attributes MainWindow:
@AddNewObject* popupWidget_create;@Constructor MainWindow:
@popupWidget_create = new AddNewObject(ui->btn_new);
popupWidget_create->setWindowFlags(Qt::Popup);@Button Click Slot:
@popupWidget_create->move(x,y);
popupWidget_create->show();@StyleSheet:
@QPushButton {
background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgb(230, 230, 230), stop:1 rgba(250, 250, 250));
border-color: rgb(150, 150, 150);
border-width: 1px;
border-style: outset;
border-radius: 0px;
padding: 3px;
}QPushButton:hover {
background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgb(41, 128, 185), stop:1 rgba(52, 152, 219));
}QPushButton:pressed{
border-style: inset;
}@The code isnt complex at all....
Even the Widget is simple... -
where is the the stylesheet set?
Do you have any eventfilters installed, etc.? -
Perhaps it is because QT Hover is triggert by entering and leaving a Area and not by Checking / Polling if the Cursor intersects the Area?
In This Case it could be that when I'm calling "show" that the Widget takes the focus of the application and even when I'm leaving the Area of the origin-Button QT wont recognize because of the Widget I'm currently showing?
Could that be? ;) -
tried to reproduce the issue with the code you've posted:
@
QPushButton* btn = new QPushButton("Open Dialog");
btn->setStyleSheet(
"QPushButton {"
"background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgb(230, 230, 230), stop:1 rgba(250, 250, 250));"
"border-color: rgb(150, 150, 150);"
"border-width: 1px;"
"border-style: outset;"
"border-radius: 0px;"
"padding: 3px;"
"}"
"QPushButton:hover {"
"background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0, stop:0 rgb(41, 128, 185), stop:1 rgba(52, 152, 219));"
"}"
"QPushButton:pressed{"
"border-style: inset;"
"}"
);
connect(btn, SIGNAL(clicked()), this, SLOT(openDialogSlot()));
@
@
void openDialog()
{
QWidget* w = new QWidget(btn , Qt::Popup );
w->move(btn->mapToGlobal(QPoint(10,10)));
w->show();
}
@Everything works as expected. When the popup is opened, the button gets the blue background removed.
(Win7, Qt 5.4) -
have you a chance to test your project on another OS?