Results 1 to 2 of 2

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

  1. #1
    Join Date
    Apr 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy How do you scale a pen so that the pen width appears constant when the view is scaled

    Here's my QGraphicsView code:

    Qt Code:
    1. def wheelEvent(self, event):
    2. if QApplication.keyboardModifiers() & (Qt.ControlModifier | Qt.ShiftModifier):
    3. self.setTransformationAnchor(self.AnchorUnderMouse)
    4. #Scale the view / do the zoom
    5. scaleFactor = 1.08
    6.  
    7. if event.angleDelta().y() > 0:
    8. #Zoom in
    9. self.scale(scaleFactor, scaleFactor)
    10. else:
    11. self.scale(1.0/scaleFactor, 1.0/scaleFactor)
    12.  
    13. #Assumes scaleX = scaleY
    14. def scale(self, scaleX, scaleY):
    15. self.scene().viewScale(scaleX)
    16. QGraphicsView.scale(self, scaleX, scaleY)
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. def viewScale(self, scale):
    2. #self.pen.setWidth(1.0 / scale)
    3. self.pen = QPen(self.color, 1.0 / scale)
    To copy to clipboard, switch view to plain text mode 

    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...

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do you scale a pen so that the pen width appears constant when the view is sc


Similar Threads

  1. Replies: 0
    Last Post: 14th October 2013, 22:19
  2. Replies: 0
    Last Post: 18th August 2013, 18:07
  3. yLeft axis constant width
    By baray98 in forum Qwt
    Replies: 4
    Last Post: 4th January 2013, 16:40
  4. Auto-adjusting height of a constant width window
    By akiross in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 01:46
  5. Replies: 1
    Last Post: 28th January 2009, 14:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.