Disable background scaling for a QGraphicsView/QGraphicsScene
-
Basically what I'm looking to do is replicate photoshop's transparency pattern in a QGraphicsScene, but when I scale the scene, the background scales also. I subclassed QGraphicsView and set it's background brush (as I understand it, it overrides the scene's background brush) but that didn't work either. I also tried overriding the drawBackground event in my subclassed QGraphicsView like so:
@
void FontPageView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->fillRect(rect, backgroundBrush());
}
@
but that still scaled the background. Does anyone know how I could keep the background image from scaling? -
[quote author="msx_br" date="1331514413"]Look at:
Examples -> Elastic Nodes Example -> graphicsview/elasticnodes/graphwidget.cpp
In the drawBackground() the examples shows how to paint directly in the QPainter.
So you can apply the scale factor as you want...
[/quote]
Thanks, but that doesn't really help. I am already drawing directly to the QPainter of the QGraphicsView exactly like they are. Their background gradient also scales.
Edit:
I see now that the QPainter has a scale, so all I needed to do was keep track of the scaling manually and inverse the scaling right before drawing the background and rescale right after, like so:@void FontPageView::drawBackground(QPainter *painter, const QRectF &rect)
{
QRectF sceneRect = this->sceneRect();QRectF bgrects = sceneRect; //scale the rectangle so that it actually covers the area it's supposed to bgrects.setBottomRight(bgrects.bottomRight() * scalefact); painter->scale(1/scalefact, 1/scalefact); painter->fillRect(bgrects, bgbr); painter->scale(scalefact, scalefact);
}@
-
Maybe QGraphicsItem::ItemIgnoresTransformations is what you are looking for.