Skip to content

Commit 3c7b74f

Browse files
committedApr 5, 2018
Allow clicking hyperlinks in HTML text edit widget
1 parent 7e6f423 commit 3c7b74f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
 

‎src/gui/editorwidgets/qgstexteditwrapper.cpp

Lines changed: 6 additions & 2 deletions
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,7 +100,7 @@ QWidget *QgsTextEditWrapper::createWidget( QWidget *parent )
100100

101101
void QgsTextEditWrapper::initWidget( QWidget *editor )
102102
{
103-
mTextEdit = qobject_cast<QTextEdit *>( editor );
103+
mTextEdit = qobject_cast<QTextBrowser *>( editor );
104104
mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
105105
mLineEdit = qobject_cast<QLineEdit *>( editor );
106106

@@ -223,7 +223,11 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
223223
if ( val != value() )
224224
{
225225
if ( config( QStringLiteral( "UseHtml" ) ).toBool() )
226+
{
226227
mTextEdit->setHtml( v );
228+
mTextEdit->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
229+
mTextEdit->setOpenExternalLinks( true );
230+
}
227231
else
228232
mTextEdit->setPlainText( v );
229233
}

‎src/gui/editorwidgets/qgstexteditwrapper.h

Lines changed: 2 additions & 2 deletions
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,7 +68,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
6868
void textChanged( const QString &text );
6969

7070
private:
71-
QTextEdit *mTextEdit = nullptr;
71+
QTextBrowser *mTextEdit = nullptr;
7272
QPlainTextEdit *mPlainTextEdit = nullptr;
7373
QLineEdit *mLineEdit = nullptr;
7474
QPalette mReadOnlyPalette;

0 commit comments

Comments
 (0)
Please sign in to comment.