[Interest] QGraphicsView and ViewPortMargin question

Ch'Gans chgans at gna.org
Sat Feb 20 12:39:52 CET 2016


Hi There,

I have sub-classed a QGraphicsView to add some custom rulers on the
top and on the left.
For this I've followed the principle used here [1], basically what's
done there is:
- set a QGridLayout to the QGV
- Add an horizontal ruler at top and left
- set QGV's viewPort as the "central widget"
- set QGV's ViewPortMargin (23 pixels, which is the space needed by my rulers

My implementation of the rulers is actually different, it only needs
to know the scene coordinates of the displayed area, and the scene
position of the mouse cursor to decide where to draw the major/minor
ticks and the cursor indicator.

Visually it does the job pretty well, but now I'm having problem with
map{To/Form}{Scene/Global}. It seems that QGV mapping function doesn't
take into account this new viewport margins.

Doeas anyone have any tip on how to get the information needed by my 2 rulers?

I have an auxiliary question as well, how to get the scene rect
displayed by the QVG which would take into account the space "eaten"
by the scroll bars? QGV::geometry() doesn't seems to return the
exposed area, not does QGV::viewPort::geometry().

Any help appreciated, in any form (docs, blog, implementation example, ...)

Chris

[1] https://kernelcoder.wordpress.com/2010/08/25/how-to-insert-ruler-scale-type-widget-into-a-qabstractscrollarea-type-widget/



More information about the Interest mailing list