Results 1 to 5 of 5

Thread: QTextEdit API questions (plain text)

  1. #1
    Join Date
    May 2006
    Posts
    2
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit API questions (plain text)

    I have used Qt before. Now I needed it again for a simple application that uses Qt4 QTextEdit to display plain text.

    I ran into two problems:

    undo () method vanished in Qt4
    Where did it go? Qt3 porting documentation to Qt4 recommends to use Qt3 compatibility libraries or port to Qt4. It does not say how to port it.

    setting a single font for QTextEdit is problematic
    It is very confusing that both QTextDocument and QTextEdit has font setting methods, it looks like a poor design to me. Besides, they don't work for plain text. The only thing that for me is QTextEdit is: selectAll, setCurrentFont.

    The problem with this nasty approach is that the text remains selected (there is no unselect method in QTextEdit).

    Another problem with this approach that is using setCurrentFont: when user deletes all text from QTextEdit the default Arial font comes back which is not particularily good for plain text display

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextEdit API questions (plain text)

    Quote Originally Posted by Gaspar
    undo () method vanished in Qt4
    Where did it go? Qt3 porting documentation to Qt4 recommends to use Qt3 compatibility libraries or port to Qt4. It does not say how to port it.
    New QTextDocument class represents a rich text document, the content of a text edit. Undo/redo operations can be performed on the document:
    Qt Code:
    1. textEdit->document()->undo();
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Gaspar
    setting a single font for QTextEdit is problematic
    You may use QWidget::setFont() to change the font of the whole widget:
    Qt Code:
    1. textEdit->setFont(font);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Gaspar (17th May 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit API questions (plain text)

    Quote Originally Posted by jpn
    You may use QWidget::setFont() to change the font of the whole widget:
    Qt Code:
    1. textEdit->setFont(font);
    To copy to clipboard, switch view to plain text mode 
    I think QTextDocument::setDefaultFont() would be better...
    Qt Code:
    1. textEdit->document()->setDefaultFont(font);
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

  5. The following user says thank you to fullmetalcoder for this useful post:

    Gaspar (17th May 2006)

  6. #4
    Join Date
    May 2006
    Posts
    2
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit API questions (plain text)

    Thank you very much for the quick response.

    textEdit->document()->undo() completely solved the first problem. QTextDocument was not even in scope when I was looking for text editing operations

    textEdit->document()->setDefaultFont(font) mostly solved the font problem. I am still having some problems when pasting rich text into my plain text window -- it appears as rich text, but I can put up with that.

    Maybe QTextEdit is an overkill for plain text...

  7. #5
    Join Date
    Jan 2006
    Location
    South Carolina, USA
    Posts
    34
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit API questions (plain text)

    Quote Originally Posted by Gaspar
    Thank you very much for the quick response.

    textEdit->document()->undo() completely solved the first problem. QTextDocument was not even in scope when I was looking for text editing operations

    textEdit->document()->setDefaultFont(font) mostly solved the font problem. I am still having some problems when pasting rich text into my plain text window -- it appears as rich text, but I can put up with that.

    Maybe QTextEdit is an overkill for plain text...
    Try setting this property of QTextEdit: http://doc.trolltech.com/4.1/qtexted...tRichText-prop

  8. The following user says thank you to michael for this useful post:

    Gaspar (17th May 2006)

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. Replies: 2
    Last Post: 30th December 2008, 22:35
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 17:45
  5. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05

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.