PDA

View Full Version : How do you scale a pen so that the pen width appears constant when the view is scaled



enjoysmath
9th August 2015, 21:41
Here's my QGraphicsView code:


def wheelEvent(self, event):
if QApplication.keyboardModifiers() & (Qt.ControlModifier | Qt.ShiftModifier):
self.setTransformationAnchor(self.AnchorUnderMouse )
#Scale the view / do the zoom
scaleFactor = 1.08

if event.angleDelta().y() > 0:
#Zoom in
self.scale(scaleFactor, scaleFactor)
else:
self.scale(1.0/scaleFactor, 1.0/scaleFactor)

#Assumes scaleX = scaleY
def scale(self, scaleX, scaleY):
self.scene().viewScale(scaleX)
QGraphicsView.scale(self, scaleX, scaleY)

viewScale() of scene() in turn calls viewScale of SnapGridGraphicsItem:


def viewScale(self, scale):
#self.pen.setWidth(1.0 / scale)
self.pen = QPen(self.color, 1.0 / scale)

I've also tried multiplying 1.0 / scale x pen.width() and the same result happens: nothing - lines are still scaled with zoom action. Please help! :|

I also already have ItemIgnoresGeometricTransformations enabled for SnapGridGraphicsItem...

d_stranz
10th August 2015, 23:38
Try QPen::setCosmetic().