diff --git a/src/gui/qgsrichtexteditor.cpp b/src/gui/qgsrichtexteditor.cpp index d8775783886f..a2b7115d3ad0 100644 --- a/src/gui/qgsrichtexteditor.cpp +++ b/src/gui/qgsrichtexteditor.cpp @@ -752,16 +752,21 @@ void QgsRichTextEditor::setText( const QString &text ) { if ( text.isEmpty() ) { - setPlainText( text ); + mTextEdit->setPlainText( text ); + mSourceEdit->clear(); return; } - if ( text[0] == '<' ) + + const thread_local QRegularExpression sIsHtmlRx( QStringLiteral( "^\\s*<" ) ); + if ( sIsHtmlRx.match( text ).hasMatch() ) { - setHtml( text ); + mTextEdit->setHtml( text ); + mSourceEdit->setText( text ); } else { - setPlainText( text ); + mTextEdit->setPlainText( text ); + mSourceEdit->setText( text ); } } diff --git a/src/gui/qgsrichtexteditor.h b/src/gui/qgsrichtexteditor.h index c83551ddeda1..37968593d737 100644 --- a/src/gui/qgsrichtexteditor.h +++ b/src/gui/qgsrichtexteditor.h @@ -162,8 +162,6 @@ class GUI_EXPORT QgsRichTextEditor : public QWidget, protected Ui::QgsRichTextEd void focusInEvent( QFocusEvent *event ) override; private slots: - void setPlainText( const QString &text ) { mTextEdit->setPlainText( text ); } - void setHtml( const QString &text ) { mTextEdit->setHtml( text ); } void textRemoveFormat(); void textRemoveAllFormat(); void textBold();