Results 1 to 4 of 4

Thread: Scaling of pen width in QGraphicsView

  1. #1
    Join Date
    Jan 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Scaling of pen width in QGraphicsView

    I am following the examples in Chapter 7 of Johan Thelin's book "Foundations of Qt Development". Simply put, I am creating a QQraphicsRectItem that is added to a QGraphicsScene as part of a QGraphicsView. I can then interact with the RectItem through handles that are also detailed in Chapter 7 of that book. All works fine, except large scaling. The rectangle expands and contracts appropriately but so does the line width of the border of the rectangle and any fill pattern is also scaled. With a pen width set to 1, a large horizontal drag expanding the width of the rectangle also results in the two side borders getting expanded to an apparent pen width of like 3 to 4. My question is whether I can change the size of the rectangle while keeping the pen width at 1 or whatever size I choose?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scaling of pen width in QGraphicsView

    Yes. Set the pen as "cosmetic" and it will remain one pixel wide regardless of the transformation.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scaling of pen width in QGraphicsView

    A pen width of 0 is "cosmetic", and will always be one pixel/dot wide.

  4. #4
    Join Date
    Jan 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scaling of pen width in QGraphicsView

    wysota and BrandyBuck,

    Thanks for the reply. The 0 width cosmetic pen works as you said and is independent of any painter transformations. I had seen the o widthe pen in the documentation a month ago or so and wondered why anyone would ever use a 0 width pen. I didn't read close enough. Again thanks.

Similar Threads

  1. widget qgraphicsview scaling
    By mistertoony in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2007, 22:46
  2. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.