Results 1 to 5 of 5

Thread: QTextEdit

  1. #1
    Join Date
    Apr 2007
    Location
    Bangalore,India
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face QTextEdit

    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
    Veda

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit

    Use:
    Qt Code:
    1. textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    2. textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    To copy to clipboard, switch view to plain text mode 

    Regards

  3. #3
    Join Date
    Apr 2007
    Location
    Bangalore,India
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QTextEdit

    Quote Originally Posted by marcel View Post
    Use:
    Qt Code:
    1. textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    2. textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    To copy to clipboard, switch view to plain text mode 

    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


    Qt Code:
    1. QTextEdit *text = new QTextEdit(window);
    2. text->resize(640, 30);
    3. text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    4. qDebug() << "before " <<text->width();
    5. text->setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB
    6. BBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCRRRRRRRRRRRRRR
    7. RRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
    8. GGGGGGGGGGGGGGGGGGGGGGGGGJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
    9. JJJJKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");
    10. qDebug() << "After " <<text->width();
    11. int ht = text->heightForWidth(text->width());
    12. if(ht > 20)
    13. text->resize(text->width(), ht);
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by veda; 10th September 2007 at 14:40.
    Veda

  4. #4
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit

    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?

  5. #5
    Join Date
    Apr 2007
    Location
    Bangalore,India
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit

    Quote Originally Posted by elcuco View Post
    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 ???
    Veda

Similar Threads

  1. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 09:25
  2. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 17:55
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07:03
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 19:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 15:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.