QGraphicsView background color different from QGraphicsScene
-
Hi,
I'd like to paint the background of
QGraphicsView
in a different color than I'm using inQGraphicsScene::drawBackground()
. I usedrawBackground()
for some custom drawing insceneRect()
so usingsetBackgroundBrush()
is out of question.How can I do this? Any tips?
Thanks a lot!
-
@wazzdaman
There is void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect). It'svirtual protected
.When you say " I use
drawBackground()
..." are you talking about onQGraphicsScene
orQGraphicsView
? View defaults to scene, but you override view one if you want different background. -
Thanks for your comments! I override
QGraphicsScene::drawBackground()
for my purposes.It turned out it's easier to solve this issue than I thought. I just changed my code in
drawBackground()
to this code and it worked perfectly:painter->fillRect(rect, QBrush(Qt::lightGray)); painter->setClipRect(sceneRect() & rect); painter->fillRect(sceneRect(), Qt::white);
Is there any simpler way to do this?
-
@wazzdaman said in QGraphicsView background color different from QGraphicsScene:
I'd like to paint the background of
QGraphicsView
in a different colorSince you wrote this I would expect you to be overriding
QGraphicsView::drawBackground()
for this,rather thanregardless of what you might be doing inQGraphicsView::drawScene()
,QGraphicsScene::drawBackground()
. -