PDA

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



tonnot
5th September 2011, 19:41
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 ?

wysota
6th September 2011, 00:28
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.

tonnot
6th September 2011, 08:14
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

wysota
6th September 2011, 09:55
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.

tonnot
6th September 2011, 11:34
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.

wysota
6th September 2011, 12:17
The zoom should determine the transform for the pen size, there should be no need to alter it per item.