PDA

View Full Version : QTextEdit API questions (plain text)



Gaspar
15th May 2006, 03:30
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:

jpn
15th May 2006, 07:25
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:

textEdit->document()->undo();


setting a single font for QTextEdit is problematic
You may use QWidget::setFont() to change the font of the whole widget:

textEdit->setFont(font);

fullmetalcoder
15th May 2006, 09:24
You may use QWidget::setFont() to change the font of the whole widget:

textEdit->setFont(font);

I think QTextDocument::setDefaultFont() would be better...

textEdit->document()->setDefaultFont(font);

Gaspar
16th May 2006, 01:56
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...

michael
16th May 2006, 06:03
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/qtextedit.html#acceptRichText-prop