I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider
void paintEvent(QPaintEvent *e) {
QPainter painter(this);
painter.begin(this);
painter.setBrush(/*not important*/);
// This covers up the control. How do I make it so the color is in
// the background and the control is still visible?
painter.drawRect(rect());
painter.end();
}
To set the background of a widget you could set the style sheet:
The following will set the background of the widget, allowing you to do more:
And btw. the following two lines of your sample code will yield a warning:
Namely this one using GCC:
So make sure, as I do in my example, that you either do
QPainter painter(this)
orpainter.begin(this)
.