In PyQt, I have a QGraphicsScene to which I add a rectangle with one of the standard QBrush fill patterns, in this case Qt.Dense7Pattern. This shows up as expected when the scene is displayed at original 1:1 scale: the "dots" that make up the Dense7Pattern are some number of pixels apart from each other, let's say 5 pixels apart just to pick a number. Also, let's say the original rectangle is 50 pixels wide and 50 pixels tall.
When I zoom in on that scene, let's say by a factor of 2, making the filled rectangle now appear 100x100 pixels, I would like the dots of the fill pattern to still appear 5 pixels apart, but, Qt zooms in on the static fill pattern too, making the dots of the fill pattern appear 10 pixels apart.
This question looks similar. Apparently you can apply a transform (including scale) to a brush's pixmap fill pattern, but, it doesn't seem to apply to the brush's 'standard' fill pattern. I did the subclass and changed the brush's transform in the paint method, but no luck:
The entire subclass (hopefully I did everything that's necessary):
class customFillPolygonItem(QGraphicsPolygonItem):
def paint(self,painter,option,widget=None):
# from here, painter.setBrush affects shapes drawn directly in this function;
# self.setBrush affects the call to super().paint
newBrush=QBrush(painter.brush())
newBrush.setTransform(QTransform(painter.worldTransform().inverted()[0]))
self.setBrush(newBrush)
painter.setBrush(newBrush)
painter.drawRect(QRectF(0,0,50,50)) # draw a reality-check object
super(customFillPolygonItem,self).paint(painter,option,widget)
Then I just make an instance of it from above using
myItem=customFillPolygonItem(QPolygonF(...
myItem.setBrush(QBrush(Qt.Dense7Pattern))
myScene.addItem(myItem)
So - is it possible to apply the scale to the a brush's standard fill pattern? This would be similar to QBrush.setFlag(ItemIgnoresTransformations) but such a thing does not exist... you can only set that flag on the entire item (rectangle in this case).
Workarounds might include: - use ItemIgnoresTransformations and manually transform the actual rectangle vertices as needed - make a qpixmap out of each standard fill pattern, then use that pixmap as the brush in which case it should scale as in the question mentioned above
But of course it would be nice to find the simplest solution.
UPDATE: Schollii answers the question that was asked; his suggestion to look in to alpha values also led to the solution to the larger issue I was having in this particular case - to create different grayscales, spelled out in the solution I posted, which is not actually a solution to the question I asked. Anyway, thanks!