Results 1 to 6 of 6

Thread: How to set pen for a QgraphicsView and let my items use them from painter received ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to set pen for a QgraphicsView and let my items use them from painter received ?

    I have a - QgraphicsView- QgraphicsScene - QgraphicsItems schema.
    I have a painter object at QgraphicsView and other at QgraphicsView, I think that it must be the same of course.

    Can I set-use the pen of this *painter at my qgraphicsitem paint() or at graphicsview background event ?
    I tried to set the pen inside my graphicsview background event, but it seems to be 'volatile' .

    Any idea ?

  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: How to set pen for a QgraphicsView and let my items use them from painter receive

    I'm not sure I understand what you mean but if you mean that you want to set painter properties in drawBackground() and expect them to persist until some item's paint() call then it won't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set pen for a QgraphicsView and let my items use them from painter receive

    As drawbackground paints the background before the items be drawed, I think it can be a good place to say to the painter the global pen width. Depending of the 'zoom' I need to set how many meters have 1 pixel, to draw the width of my polylines rightly. (variable width) (Yes I know the meaning of setwidth to zero and the 'cosmetic' function).
    I need a 'global' way to setup the pen width (and maybe other painter-draw properties). I would not want to set this inside every graphic item.
    So, ....., is there any way to do this ?
    Thanks

  4. #4
    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: How to set pen for a QgraphicsView and let my items use them from painter receive

    Quote Originally Posted by tonnot View Post
    As drawbackground paints the background before the items be drawed, I think it can be a good place to say to the painter the global pen width.
    No, because each item can have a different pen, brush and a bunch of other things. You can override this behaviour by setting DontSavePainterState on the view but then you will have to keep the painter clean yourself.

    I need a 'global' way to setup the pen width (and maybe other painter-draw properties). I would not want to set this inside every graphic item.
    You're lazy. Do it properly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set pen for a QgraphicsView and let my items use them from painter receive

    No, it is not a lazy problem.
    If I have 1 million of items, I think it would be better to set the pen width for the whole million than setting the pen 1 miilion times.
    Thanks.

  6. #6
    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: How to set pen for a QgraphicsView and let my items use them from painter receive

    The zoom should determine the transform for the pen size, there should be no need to alter it per item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Thread-safety of QGraphicsView::items.
    By Nicuvëo in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2011, 12:24
  2. QGraphicsView + steady Items
    By medved6 in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2010, 19:20
  3. Position of Items in QGraphicsScene/QGraphicsView
    By StefanK2 in forum Qt Programming
    Replies: 11
    Last Post: 7th July 2009, 14:04
  4. QGraphicsView overlapping items
    By juliarg in forum Newbie
    Replies: 1
    Last Post: 5th April 2007, 09:35

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.