[Qt-interest] QPlainTextEdit has broken layout after hide(), show()
Nikos Chantziaras
realnc at arcor.de
Wed Jun 22 07:53:02 CEST 2011
On 06/21/2011 10:24 PM, Kevin Funk wrote:
> Tuesday 21 June 2011, Nikos Chantziaras<realnc at arcor.de>:
>> I came across a strange glitch with QPlainTextEdit: When I modify it
>> with insertPlainText() while the QPTE is hidden and then show() it, the
>> contents are all messed up and will only show correctly is the user
>> resizes the widget. Calling update() after show() does not help.
>> Calling document()->setModified() and/or document()->markContentsDirty()
>> doesn't help either.
>>
>> Any solutions to this? And should this be considered a bug that should
>> be reported?
>
> I think I had to solve the same issue just recently:
>
> You could try this code to force a re-layout of the QTPE contents:
> QEvent e(QEvent::FontChange);
> QApplication::sendEvent(textEdit,&e);
>
> This is from [1].
>
> I personally think this should be considered a bug in
> QTextDocument/QAbstractTextDocumentLayout.
>
> [1] http://lists.trolltech.com/qt4-preview-feedback/2005-02/thread01030-0.html
Doesn't work, unfortunately. The only way I found that works is quite
ugly (and probably slow):
log->show();
log->setPlainText(log->toPlainText());
log->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
I'm not sure if this has anything to do with the way I insert text into
it though:
log->moveCursor(QTextCursor::End);
log->insertPlainText(logMsg);
log->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
I certainly can't see anything wrong with it.
More information about the Qt-interest-old
mailing list