Skip to content

Commit

Permalink
Merge pull request #6753 from m-kuhn/textbrowser
Browse files Browse the repository at this point in the history
Allow clicking hyperlinks in HTML text edit widget
  • Loading branch information
m-kuhn committed Apr 9, 2018
2 parents e627b84 + 5ad1633 commit bff8976
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/gui/editorwidgets/qgstexteditwrapper.cpp
Expand Up @@ -85,7 +85,7 @@ QWidget *QgsTextEditWrapper::createWidget( QWidget *parent )
{
if ( config( QStringLiteral( "UseHtml" ) ).toBool() )
{
return new QTextEdit( parent );
return new QTextBrowser( parent );
}
else
{
Expand All @@ -100,6 +100,7 @@ QWidget *QgsTextEditWrapper::createWidget( QWidget *parent )

void QgsTextEditWrapper::initWidget( QWidget *editor )
{
mTextBrowser = qobject_cast<QTextBrowser *>( editor );
mTextEdit = qobject_cast<QTextEdit *>( editor );
mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
mLineEdit = qobject_cast<QLineEdit *>( editor );
Expand Down Expand Up @@ -223,7 +224,14 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
if ( val != value() )
{
if ( config( QStringLiteral( "UseHtml" ) ).toBool() )
{
mTextEdit->setHtml( v );
if ( mTextBrowser )
{
mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
mTextBrowser->setOpenExternalLinks( true );
}
}
else
mTextEdit->setPlainText( v );
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/qgstexteditwrapper.h
Expand Up @@ -20,7 +20,7 @@

#include <QLineEdit>
#include <QPlainTextEdit>
#include <QTextEdit>
#include <QTextBrowser>
#include "qgis_gui.h"

SIP_NO_FILE
Expand Down Expand Up @@ -68,6 +68,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
void textChanged( const QString &text );

private:
QTextBrowser *mTextBrowser = nullptr;
QTextEdit *mTextEdit = nullptr;
QPlainTextEdit *mPlainTextEdit = nullptr;
QLineEdit *mLineEdit = nullptr;
Expand Down

0 comments on commit bff8976

Please sign in to comment.