PDA

View Full Version : QTextEdit



veda
10th September 2007, 11:08
Hello friends,

I am implementing a header and footer in my application...

I an using QTextEdit for header and footer....

Now My problem is..

How do i disable the scrollbar which will automatically appears as the data
in the TextEdit increases,

I want the TextEdit to resize itself as the content increases...

In Qt3 we had heightForWidth function to do this ....

How can I achieve the same in Qt4..

Thanks

marcel
10th September 2007, 11:17
Use:


textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;


Regards

veda
10th September 2007, 11:27
Use:


textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;




I am able to remove the scrollBar now,
But How to resize the TextEdit based on the content of the edit...

what is the equivalent functionality of heightForWidth



QTextEdit *text = new QTextEdit(window);
text->resize(640, 30);
text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
qDebug() << "before " <<text->width();
text->setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB
BBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCRRRRRR RRRRRRRR
RRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GG
GGGGGGGGGGGGGGGGGGGGGGGGGJJJJJJJJJJJJJJJJJJJJJJJJJ JJJJJJJJJJJJJJJJJJJJ
JJJJKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");
qDebug() << "After " <<text->width();
int ht = text->heightForWidth(text->width());
if(ht > 20)
text->resize(text->width(), ht);

In the above code the width and height remain the same before and after the text is inserted....

How could I resize the TextEdit based on content .

And How can I get the total number of lines in TextEdit.

Thanks

elcuco
10th September 2007, 19:17
If you want a widget that can display rich text and resizes it self to the contents of the text, how about using QLabel instead of QTextEdit?

veda
11th September 2007, 07:30
If you want a widget that can display rich text and resizes it self to the contents of the text, how about using QLabel instead of QTextEdit?

As I told I need a functionality of the header and footer....
where i can edit, cut , copy , paste , as well as to apply the fontsize, color....
How can we edit in QLabel ???