Well, I didn't find any explanations or suggestions, so I have found solution by myself.
To highlight button in QWidgetAction
, I added dynamic property, like in the code below in a place where buttons were constucted:
m_pasteButton->setProperty("mouseHover", false);
Then, In installed filters on the buttons and catch Enter
and Leave
events to figure out when the mouse is hovered or not:
bool CustomWidgetAction::eventFilter(QObject* object, QEvent* event)
{
if (object == m_cutButton)
{
QEvent::Type t = event->type();
if (t == QEvent::Enter)
{
QWidget* w = qobject_cast<QWidget*>(object);
w->setProperty("mouseHover", true);
w->polish(w);
}
else if (t == QEvent::Leave)
{
QWidget* w = qobject_cast<QWidget*>(object);
w->setProperty("mouseHover", false);
w->polish(w);
}
}
return QWidget::eventFilter(object, event);
}
And then, in the css, I added some rules to set hover effect:
CustomWidgetAction QPushButton[mouseHover="true"]:enabled
{
background: HOVERED_CONTEXT_BUTTON_GRADIENT;
border-color: HOVERED_ACTIVE_CONTEXT_BUTTON_BORDER;
}
CustomWidgetAction QPushButton[mouseHover="false"]:enabled
{
background: none;
border-color: ACTIVE_CONTEXT_BUTTON_BORDER;
}