I have a custom QWidget (actually obtained from QAbstractButton ) for which I have to implement my own paintEvent . How to use the information in the style sheet?
For example, suppose someone defines the following stylesheet that applies (directly or through inheritance) to my custom class:
QAbstractButton { font-weight: bold; background-color: red } QAbstractButton:checked { background-color: blue }
In my paintEvent method, how can I get the correct background color for the displayed state?
void MyButton::paintEvent(QPaintEvent *) { ensurePolished();
I assume that I need something like:
if (isChecked()) { // painter.fillRect(rect(), ???); // // style()->drawPrimitive(???, ...); // // QStyleOptionButton opt; // opt.initFrom(this); // QBrush bg_brush = opt.??? // painter.fillRect(rect(), bg_brush); // // ??? } else { painter.fillRect(rect(), painter.background()); }
How to get a brush for the background of the checked state that Qt allowed from stylesheets?
source share