Solved QStyleOptionButton cloud be set background color?
-
I try to use setStyleSheet in the delegate
setStyleSheet("QPushButton{background-color:red}");
it still doesn't work....
-
Hi,
You are modifying thepainter
object but you are then calling the style of QApplication to paint. Why don't use usepainter
?Misread the code.
[edit: SGaist]
-
@SGaist
Thank you..you mean that's create a new painter?
painter->setBrush(QColor(Qt::red)); //it's still unuseful...
It doesn't work...
-
Sorry, my bad, I misread your code.
What platform are you on ?
With which version of Qt ?Can you also show what you are currently getting ?
-
You might want to call
painter->fillRect(btn.rect, btn.palette.brush(QPalette::Button));
Before drawing the button on top of it.
-
@SGaist
win7 + Qt5.9 + mingw32I had tried
if(option.widget != NULL) { painter->fillRect(btn.rect,btn.palette.brush(QPalette::Button)); //It doesn't work QApplication::style()->drawControl(QStyle::CE_PushButton,&btn,painter); } else option.widget->style();
I also tried
if(option.widget != NULL) { btn.palette.setBrush(QPalette::Background,QBrush(QColor(Qt::red))); painter->fillRect(btn.rect,btn.palette.brush(QPalette::Button)); //unused....... QApplication::style()->drawControl(QStyle::CE_PushButton,&btn,painter); } else option.widget->style();
It's a question ~。~ -
Could someone give me help......
on those days,I trid to use a pix to replace the button,but when I clicked the button(It's is a pix in fact),it doesn't look like a button,because the button will changed when it clicked by mouse but pix not
More important,my boss denied my plan that's replace the button by a pix....
-
Hi
I think i used QStyle::CE_PushButtonLabel instead to get it to be transparent as
QStyle::CE_PushButton ignored all QBrush.
If that fails too, you could use icon on button to show state. -
@qazaq408 said in QStyleOptionButton cloud be set background color?:
btn.palette.setBrush(QPalette::Background,QBrush(QColor(Qt::red)));
painter->fillRect(btn.rect,btn.palette.brush(QPalette::Button)); //unused.......Have you tried
painter->fillRect(btn.rect, btn.palette.brush(QPalette::Background));
instead of
painter->fillRect(btn.rect, btn.palette.brush(QPalette::Button)); -
@JohnMPaine
tried....
And then ,the whole button has filled....the txt of button can't be seen.....