PDA

View Full Version : Setting QGraphicsTextItem height?



Dutch112
10th August 2009, 18:04
Does anyone know how to specify the height of a QGraphicsTextItem? I've tried a number of ways and nothing seems to work.



QGraphicsTextItem text;
text.document()->setPageSize( QSizeF( 300,40) );

qreal w = text.document()->size().width(); // 300 - correct
qreal h = text.document()->size().height(); // 22 - why???


I've also tried setting the size property directly on QTextDocument but the same thing happens, it accepts the width but not the height.

Lykurg
10th August 2009, 19:18
Why? Have a look into the docs! There you can find for size:

Returns the actual size of the document. This is equivalent to documentLayout()->documentSize();
If you want the size of the document use QTextDocument::pageSize().

Dutch112
10th August 2009, 19:32
Returns the actual size of the document.

That is what I care about, the actual size. The problem is, I am specifying the size I want it to be - 40 - but it doesn't take.

The actual size, not page size, seems to determine how it will be drawn. So I could do this:



text.document()->setPageSize(QSizeF(300,300));


and it will be drawn on screen with a width of 300, and a height of 28. I want it to draw with a height of 300.

robertkun
11th August 2009, 11:03
change the font point size ,can change the height of the QGraphicsTextItem .
This function would help you?