[Qt-creator] TextEditor plugin: how to set QTextDocument in BaseTextEditorWidget?

Vitali Baumtrok aedit at baumtrok.de
Wed May 28 21:50:03 CEST 2014


Am 28.05.2014 21:32, schrieb Thorbjørn Lindeijer:
>
> On 28.05.2014 21:25, Thorbjørn Lindeijer wrote:
>> So what you need to do is for your text document is to make sure it has
>> this custom layout subclass set on it as well. This code is found in the
>> BaseTextDocument constructor:
>>
>>>       BaseTextDocumentLayout *documentLayout = new BaseTextDocumentLayout(d->m_document);
>>>       d->m_document->setDocumentLayout(documentLayout);

I already tried it. The ASSERT message is gone then, but the editor stays empty.

>
> Sorry, I think my instructions are rather misleading. The
> BaseTextEditorWidget is only meant to be used with a BaseTextDocument.
> You should probably not use its setTextDocument function at all, which
> only happens to be available because it's a subclass of the
> QPlainTextEdit widget.
>
> If you need to integrate a class that derives from QTextDocument, you
> should probably look into changing your own class to derive from the
> BaseTextDocument instead.
>
> Regards,
> Bjørn

Thanks for your answer. It supports my assumption that QTextDocument should not
be set.

Unfotunately I can't derive from BaseTextDocument, because the other class
(the one derived from QTextDocument) is already used a lot within other code.
I would have to rewrite everything.

What I could do is to synchronize the both documents when one is changed,
i.e. listen to the contentsChanged SIGNAL of the one document and then make
something like doc->setPlainText(mDocToSyncWith->plainText()).



More information about the Qt-creator mailing list