Qt drawRect in background
问题 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(); } 回答1: To set the background of a widget you could set the style sheet: theSlider