[Interest] QGraphicsView and ViewPortMargin question
Ch'Gans
chgans at gna.org
Mon Feb 22 00:02:56 CET 2016
On 21 February 2016 at 00:39, Ch'Gans <chgans at gna.org> wrote:
> 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
Actually, everything works as expected if I use something like:
void MyView::updateRulerCursorRanges()
{
QPointF topLeft = mapToScene(QPoint(0, 0));
QPointF bottomRight = mapToScene(QPoint(viewport()->width(),
viewport()->height()));
m_horizontalRuler->setCursorRange(topLeft.x(), bottomRight.x());
m_verticalRuler->setCursorRange(topLeft.y(), bottomRight.y());
}
void MyView::updateRulerCursorPositions()
{
QPointF pos = mapToScene(viewport()->mapFromGlobal(QCursor::pos()));
m_horizontalRuler->setCursorPosition(pos);
m_verticalRuler->setCursorPosition(pos);
}
Chris
>
> 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