Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make qt qgraphicsview scale to not affect stipple pattern?

I draw few rectangles inside the QGraphicsView ; I use custom stipple pattern for these by creating a QBrush with my QPixmap. This gets displayed with the default zoom level as expected.

When I call view->scale(), the rectangles show up bigger or smaller as I expected. However Qt has scaled the individual bits of the stipple pattern which is not expected; I expected it to draw the larger or smaller rectangle again with the brush. Eg. If I had used a stipple pattern with one pixel dot and pixel space, after zooming in, I want to see a larger rectangle but I want the same stipple pattern with same pixel gaps. Is this achievable somehow? Thanks.

like image 244
Kaniyan Avatar asked Dec 19 '12 18:12

Kaniyan


1 Answers

I ran into the same problem while developing an EDA tool companion in Qt.

After some trying, what I did (and seems to work for me) is to create a custom graphics item. On the paint method, I do:

QBrush newBrush = brush_with_pattern;
newBrush.setTransform(QTransform(painter->worldTransform().inverted()));
painter->setBrush(newBrush);

That is to apply the inverse transformation of the item to the brush (so it does not scale).

I think that the setDashOffset is only for the border of the shapes (not the fill).

like image 160
Francesc Vila Avatar answered Sep 22 '22 17:09

Francesc Vila