QSS properties for a custom widget: how to implement hovering and pressed states

I found this example on the Internet on how to implement custom properties available from QSS for custom QWidgets: https://qt-project.org/wiki/Qt_Style_Sheets_and_Custom_Painting_Example

Does anyone know how I can implement a widget to have different colors for hovering or pressed states?

The current stylesheet is as follows:

SWidget
{
 qproperty-lineColor: yellow;
 qproperty-rectColor: red;
}

I want to have something like this:

SWidget:hover
{
 qproperty-lineColor: blue;
 qproperty-rectColor: green;
}

SWidget:pressed
{
 qproperty-lineColor: orange;
 qproperty-rectColor: violet;
}

Note. I know that you can implement mouse events and change colors using qproperties specific to mouse events, for example:

SWidget
{
 qproperty-lineColor: yellow;
 qproperty-rectColor: red;
 qproperty-lineColor-hover: orange;
 qproperty-rectColor-hover: violet;
}

but I would like it to work using the original qss / css method.

Hello!

+4
1

, . QSS . .

qApp->style()->unpolish( this );
qApp->style()->polish( this );

"this" . "" QSS.

0

All Articles