PDA

View Full Version : How can i get the contents size of QTextBrowser



m_e
25th December 2006, 10:24
Is there any way to get size of the contents of QTextBrowser in Qt4?
It seems that documentLayout()->documentSize() should do this, but this function returns a negative size after I had set the html to the corresponding QTextDocument:


QTextDocument* textDoc = m_MessageBrowser->document();
textDoc->clear();
textDoc->setHtml( m_html );
qWarning( "testDoc height = %d \n", int( textDoc->documentLayout()->documentSize().height() ) ); // prints -1

wysota
25th December 2006, 11:41
Maybe you should call QTextDocument::adjustSize() first or let the widget update itself first? The document size is calculated when the layout takes place, so if you ask for it just after setting the document, it is not yet calculated.

m_e
25th December 2006, 12:25
There is no such method in Qt4.1.4 =(
I've tried to call adjustSize() for QTextBrowser, but it had no effect.
I've also tried with maximumViewportSize(), but the result was too large for my single row html table :(

wysota
25th December 2006, 13:36
There is no such method in Qt4.1.4 =(
No, it was introduced in 4.2.


I've tried to call adjustSize() for QTextBrowser, but it had no effect.
You want the size of the document, not the widget.

I've also tried with maximumViewportSize(), but the result was too large for my single row html table :(
That concerns the widget as well, not the document.

As I said, try calling repaint() or update() before you fetch the document layout size.

m_e
25th December 2006, 15:14
As I said, try calling repaint() or update() before you fetch the document layout size.
Unfortunately it doesn't work too =( Anyway thanks for help.
It seems I have to install Qt4.2...