Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
Description
Consider the following QGraphicsItem:
QRectF MyGraphicsItem::boundingRect() const
{
return QRectF(-0.5, -0.5, 1.0, 1.0);
}
void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
QFont font = painter->font();
font.setPointSizeF(0.05);
painter->setFont(font);
painter->drawText(boundingRect(), Qt::AlignCenter, tr("text"));
}
then:
QGraphicsScene scene;
scene.addItem(new MyGraphicsItem);
QGraphicsView view(&scene);
view.scale(200.0, 200.0);
It seems natural to assume that this will work, since it will work with all other graphics view primitives, and since it's the final coordinate system of the view which should determine the results, not the initial coordinate system of the item. However, the text will not show at all in the case. If you draw the text to a point rather than a into a rect, it will be painted much too large, and lowering the point size will not alter the size of the text. Also, the letters will be painted on top of each other.
If you change the coordinate system of the graphics item so that the point size is within a normal range, and then change the scale of the view accordingly, the example should work.