Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
Making a QTextEdit resize itself to fit its content


Message 1 in thread

Hi,

Sorry in advance, if this question was already answered somewhere.

I have a QTextEdit instance which I use to visualize a complex 
QTextDocument. My problem is that I would like very much to make the 
QTextEdit to resize itself as to fit its contents, is this possible ?

BTW , I am currently doing it by forcing the QTextEdit to show its 
scrollbars and getting the real 'height' and 'width' from the scrollbars 
maximum values. This works but I was wondering if exists some better, 
legal, way of doing it.

Thanks a lot.

Regards,
Hernán


--
 [ signature omitted ] 

Message 2 in thread

Did you already tried setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded) and 
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) ?

"Hernan Tylim" <htylim@xxxxxxxxxxxx> wrote in message 
news:46A4A3AD.3020706@xxxxxxxxxxxxxxx
> Hi,
>
> Sorry in advance, if this question was already answered somewhere.
>
> I have a QTextEdit instance which I use to visualize a complex 
> QTextDocument. My problem is that I would like very much to make the 
> QTextEdit to resize itself as to fit its contents, is this possible ?
>
> BTW , I am currently doing it by forcing the QTextEdit to show its 
> scrollbars and getting the real 'height' and 'width' from the scrollbars 
> maximum values. This works but I was wondering if exists some better, 
> legal, way of doing it.
>
> Thanks a lot.
>
> Regards,
> Hernán
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/ 


--
 [ signature omitted ] 

Message 3 in thread

I didn't try it but it wouldn't work because that property what it does, 
please someone correct me if I'm wrong, is to control when the 
scrollbars are shown, they don't do nothing with the size of the widget.

What I need is to being able to show a QTextEdit like we do with 
QLabels, they just adjust their size to its contents.

Thanks

Regards,
Hernán

Geofrey van Hecke wrote:
> Did you already tried setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded) and 
> setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) ?
> 
> "Hernan Tylim" <htylim@xxxxxxxxxxxx> wrote in message 
> news:46A4A3AD.3020706@xxxxxxxxxxxxxxx
>> Hi,
>>
>> Sorry in advance, if this question was already answered somewhere.
>>
>> I have a QTextEdit instance which I use to visualize a complex 
>> QTextDocument. My problem is that I would like very much to make the 
>> QTextEdit to resize itself as to fit its contents, is this possible ?
>>
>> BTW , I am currently doing it by forcing the QTextEdit to show its 
>> scrollbars and getting the real 'height' and 'width' from the scrollbars 
>> maximum values. This works but I was wondering if exists some better, 
>> legal, way of doing it.
>>
>> Thanks a lot.
>>
>> Regards,
>> Hernán
>>
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/ 
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

-- 
 [ signature omitted ] 

Message 4 in thread

tried

QTextBrowser::document()->documentLayout()->documentSize().toSize() ?

(Browser inherits edit, should work there as well, but i guess you're not 
interested in an editable widget anway)

Thomas

Am Montag, 23. Juli 2007 19:19 schrieb Hernan Tylim:
> I didn't try it but it wouldn't work because that property what it does,
> please someone correct me if I'm wrong, is to control when the
> scrollbars are shown, they don't do nothing with the size of the widget.
>
> What I need is to being able to show a QTextEdit like we do with
> QLabels, they just adjust their size to its contents.
>
> Thanks
>
> Regards,
> Hernán
>
> Geofrey van Hecke wrote:
> > Did you already tried setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded)
> > and setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) ?
> >
> > "Hernan Tylim" <htylim@xxxxxxxxxxxx> wrote in message
> > news:46A4A3AD.3020706@xxxxxxxxxxxxxxx
> >
> >> Hi,
> >>
> >> Sorry in advance, if this question was already answered somewhere.
> >>
> >> I have a QTextEdit instance which I use to visualize a complex
> >> QTextDocument. My problem is that I would like very much to make the
> >> QTextEdit to resize itself as to fit its contents, is this possible ?
> >>
> >> BTW , I am currently doing it by forcing the QTextEdit to show its
> >> scrollbars and getting the real 'height' and 'width' from the scrollbars
> >> maximum values. This works but I was wondering if exists some better,
> >> legal, way of doing it.
> >>
> >> Thanks a lot.
> >>
> >> Regards,
> >> Hernán
> >>
> >>
> >> --
> >> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> >> "unsubscribe" in the subject or the body.
> >> List archive and information: http://lists.trolltech.com/qt-interest/
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body. List archive and information:
> > http://lists.trolltech.com/qt-interest/

-- 
 [ signature omitted ] 

Message 5 in thread

Hi. This worked as a charm. Thanks!

Thomas Lübking wrote:
> tried
> 
> QTextBrowser::document()->documentLayout()->documentSize().toSize() ?
> 
> (Browser inherits edit, should work there as well, but i guess you're not 
> interested in an editable widget anway)
> 
> Thomas
> 
> Am Montag, 23. Juli 2007 19:19 schrieb Hernan Tylim:
>> I didn't try it but it wouldn't work because that property what it does,
>> please someone correct me if I'm wrong, is to control when the
>> scrollbars are shown, they don't do nothing with the size of the widget.
>>
>> What I need is to being able to show a QTextEdit like we do with
>> QLabels, they just adjust their size to its contents.
>>
>> Thanks
>>
>> Regards,
>> Hernán
>>
>> Geofrey van Hecke wrote:
>>> Did you already tried setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded)
>>> and setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) ?
>>>
>>> "Hernan Tylim" <htylim@xxxxxxxxxxxx> wrote in message
>>> news:46A4A3AD.3020706@xxxxxxxxxxxxxxx
>>>
>>>> Hi,
>>>>
>>>> Sorry in advance, if this question was already answered somewhere.
>>>>
>>>> I have a QTextEdit instance which I use to visualize a complex
>>>> QTextDocument. My problem is that I would like very much to make the
>>>> QTextEdit to resize itself as to fit its contents, is this possible ?
>>>>
>>>> BTW , I am currently doing it by forcing the QTextEdit to show its
>>>> scrollbars and getting the real 'height' and 'width' from the scrollbars
>>>> maximum values. This works but I was wondering if exists some better,
>>>> legal, way of doing it.
>>>>
>>>> Thanks a lot.
>>>>
>>>> Regards,
>>>> Hernán
>>>>
>>>>
>>>> --
>>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>>> "unsubscribe" in the subject or the body.
>>>> List archive and information: http://lists.trolltech.com/qt-interest/
>>> --
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>> "unsubscribe" in the subject or the body. List archive and information:
>>> http://lists.trolltech.com/qt-interest/
> 

-- 
 [ signature omitted ] 

Message 6 in thread

Hi Hernan,

> Sorry in advance, if this question was already answered somewhere.
> 
> I have a QTextEdit instance which I use to visualize a complex 
> QTextDocument. My problem is that I would like very much to make the 
> QTextEdit to resize itself as to fit its contents, is this possible ?
> 

Yes.

> BTW , I am currently doing it by forcing the QTextEdit to show its 
> scrollbars and getting the real 'height' and 'width' from the scrollbars 
> maximum values. This works but I was wondering if exists some better, 
> legal, way of doing it.

You could probably get the size from QTextDocument or something, but an 
easy solution would simply be QTextEdit::viewport()->size(). That one 
will give you the actual height of the content without any fiddling :-)


-- 
 [ signature omitted ] 

Message 7 in thread

This (below) is a bit of a hack, but it seems to work.

Sam Dutton

.................................................

#include <qapplication.h>
#include <qtextedit.h>



int main(int argc, char **argv)
{
	QApplication application(argc, argv);

	QTextEdit *textEdit = new QTextEdit("This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some fsfd text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some fsd fasd fsda fasd fasd fasd text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is fdsa fds afasd fasd fsda fsda fdsa fdsa fdas fdassome text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This  fdas fasd fasd fsda fsda fsda fsda fdis some text. This is some text. ");

	textEdit->show();
	const int myWidth = 200;
	textEdit->setFixedWidth(myWidth); 
	textEdit->setFixedHeight(textEdit->heightForWidth(myWidth) + 
		textEdit->currentFont().pointSize() * 2.5); // hack!
	textEdit->adjustSize();

	return application.exec();
}
 


 





SAM DUTTON
SENIOR SITE DEVELOPER

200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F 
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK

-----Original Message-----

From: Hernan Tylim [mailto:htylim@xxxxxxxxxxxx] 
Sent: Monday 23 July 2007 18:19
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Making a QTextEdit resize itself to fit its content

I didn't try it but it wouldn't work because that property what it does, please someone correct me if I'm wrong, is to control when the scrollbars are shown, they don't do nothing with the size of the widget.

What I need is to being able to show a QTextEdit like we do with QLabels, they just adjust their size to its contents.

Thanks

Regards,
Hernán

Geofrey van Hecke wrote:
> Did you already tried 
> setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded) and
> setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) ?
> 
> "Hernan Tylim" <htylim@xxxxxxxxxxxx> wrote in message 
> news:46A4A3AD.3020706@xxxxxxxxxxxxxxx
>> Hi,
>>
>> Sorry in advance, if this question was already answered somewhere.
>>
>> I have a QTextEdit instance which I use to visualize a complex 
>> QTextDocument. My problem is that I would like very much to make the 
>> QTextEdit to resize itself as to fit its contents, is this possible ?
>>
>> BTW , I am currently doing it by forcing the QTextEdit to show its 
>> scrollbars and getting the real 'height' and 'width' from the 
>> scrollbars maximum values. This works but I was wondering if exists 
>> some better, legal, way of doing it.
>>
>> Thanks a lot.
>>
>> Regards,
>> Hernán
>>
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
>> with "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

--
 [ signature omitted ]