QGraphicsView background color different from QGraphicsScene
-
Hi,
I'd like to paint the background of
QGraphicsViewin 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!
-
Hi,
I'd like to paint the background of
QGraphicsViewin 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 onQGraphicsSceneorQGraphicsView? View defaults to scene, but you override view one if you want different background. -
Hi,
I'd like to paint the background of
QGraphicsViewin 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 Try to add an openglwidget to the viewport of QGraphicsView and set different background color to it? I did not try it.
-
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?
-
Hi,
I'd like to paint the background of
QGraphicsViewin 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 said in QGraphicsView background color different from QGraphicsScene:
I'd like to paint the background of
QGraphicsViewin 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(). -
@wazzdaman said in QGraphicsView background color different from QGraphicsScene:
I'd like to paint the background of
QGraphicsViewin 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(). -
W wazzdaman has marked this topic as solved on