janus
2nd February 2009, 09:37
Hi,
I have a graphicsview that gets scaled. I want a line + text that always stays in the top left corner whatever the scaling or scrollbar position is.
I managed (with the help of some previous threads) to draw a line but the font is always scaled. Setting a pixelsize depending on scaling factor did not work. If I rescale the painter (e.g. resetTransform()) I get always the same fontsize but then I lose the point's position where to draw the text ...
void GraphicsView::drawForeground(QPainter *painter, const QRectF &rect)
{
QRectF scenerect = QRectF(mapToScene(0,0), mapToScene(width(), height()));
QPointF p1(scenerect.topLeft().x() + (10/matrix().m11()), scenerect.topLeft().y() + (10/matrix().m22()));
QPointF p2(p1.x() + (50/matrix().m11()), p1.y() + (10/matrix().m22()));
QRectF r(p1, p2);
painter->drawLine(r.topLeft(), r.topRight()); //ok
painter->drawText(r, QString::number(10)); //?
}
I have a graphicsview that gets scaled. I want a line + text that always stays in the top left corner whatever the scaling or scrollbar position is.
I managed (with the help of some previous threads) to draw a line but the font is always scaled. Setting a pixelsize depending on scaling factor did not work. If I rescale the painter (e.g. resetTransform()) I get always the same fontsize but then I lose the point's position where to draw the text ...
void GraphicsView::drawForeground(QPainter *painter, const QRectF &rect)
{
QRectF scenerect = QRectF(mapToScene(0,0), mapToScene(width(), height()));
QPointF p1(scenerect.topLeft().x() + (10/matrix().m11()), scenerect.topLeft().y() + (10/matrix().m22()));
QPointF p2(p1.x() + (50/matrix().m11()), p1.y() + (10/matrix().m22()));
QRectF r(p1, p2);
painter->drawLine(r.topLeft(), r.topRight()); //ok
painter->drawText(r, QString::number(10)); //?
}