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 :mad:
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:
Code:
textEdit->document()->undo();
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:
Code:
textEdit->setFont(font);
Re: QTextEdit API questions (plain text)
Quote:
Originally Posted by jpn
You may use QWidget::setFont() to change the font of the whole widget:
Code:
textEdit->setFont(font);
I think QTextDocument::setDefaultFont() would be better...
Code:
textEdit->document()->setDefaultFont(font);
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...
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