Skip to content

Commit bff8976

Browse files
authored
Merge pull request #6753 from m-kuhn/textbrowser
Allow clicking hyperlinks in HTML text edit widget
2 parents e627b84 + 5ad1633 commit bff8976

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/gui/editorwidgets/qgstexteditwrapper.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ QWidget *QgsTextEditWrapper::createWidget( QWidget *parent )
8585
{
8686
if ( config( QStringLiteral( "UseHtml" ) ).toBool() )
8787
{
88-
return new QTextEdit( parent );
88+
return new QTextBrowser( parent );
8989
}
9090
else
9191
{
@@ -100,6 +100,7 @@ QWidget *QgsTextEditWrapper::createWidget( QWidget *parent )
100100

101101
void QgsTextEditWrapper::initWidget( QWidget *editor )
102102
{
103+
mTextBrowser = qobject_cast<QTextBrowser *>( editor );
103104
mTextEdit = qobject_cast<QTextEdit *>( editor );
104105
mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
105106
mLineEdit = qobject_cast<QLineEdit *>( editor );
@@ -223,7 +224,14 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
223224
if ( val != value() )
224225
{
225226
if ( config( QStringLiteral( "UseHtml" ) ).toBool() )
227+
{
226228
mTextEdit->setHtml( v );
229+
if ( mTextBrowser )
230+
{
231+
mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
232+
mTextBrowser->setOpenExternalLinks( true );
233+
}
234+
}
227235
else
228236
mTextEdit->setPlainText( v );
229237
}

src/gui/editorwidgets/qgstexteditwrapper.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <QLineEdit>
2222
#include <QPlainTextEdit>
23-
#include <QTextEdit>
23+
#include <QTextBrowser>
2424
#include "qgis_gui.h"
2525

2626
SIP_NO_FILE
@@ -68,6 +68,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
6868
void textChanged( const QString &text );
6969

7070
private:
71+
QTextBrowser *mTextBrowser = nullptr;
7172
QTextEdit *mTextEdit = nullptr;
7273
QPlainTextEdit *mPlainTextEdit = nullptr;
7374
QLineEdit *mLineEdit = nullptr;

0 commit comments

Comments
 (0)