Solved how to change the left white space which QPainter doesnot draw in QWidget?
-
how to change the left white space which QPainter doesnot draw in QWidget?
i did some drawing in paintEvent, however, the left area which didnot draw remains White, now i want to change this White into the color of its parent's background color which is normally light-gray in windows. -
Hi
Show the code :)
or an image at least.
Its not easy to understand what you mean. -
eg.
void paintEvent()
{
...
painter.drawRect(rect);//rect is smaller than the QWidget size
...
}
then the area not belong to rect remains white, and i want to change this white color. -
@opengpu is your widget managed by a QLayout of any kind? Because the "White space" may be just the margins defined in the layout.
-
no, it's on Layout, but i am sure the white area is the area which i don't draw anything in paintEvent
-
Try something like this to fill the white space of your drawing.
void MyWidget::paintEvent(QPaintEvent*..) { .. .. QRect r = this->rect(); painter.setBrush(//Set the parent color); painter.drawRect(r).// draw the full background first painter.setBrush(//Set the current color); painter.drawRect(rect);//draw your rect }
-
is this inefficient?
-
i tried, and it works, thank you!