Archived:Using QTextBrowser in Qt
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
S60 5th Edition
Article
Keywords: QTextBrowser
Created: tepaa
(03 Jun 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This code snippet demonstrates how to use QTextBrowser. The QTextBrowser class extends QTextEdit and provides a rich text browser with hypertext navigation.
Note: In order to use this code, you need to have Qt installed on your platform.
Header
#include <QWidget>
#include <QTextBrowser>
#include <QVBoxLayout>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = 0);
~MyWidget();
void setText(QString);
private:
QTextBrowser* textBrowser;
};
Source
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
// Create text browser
textBrowser = new QTextBrowser(this);
// Set it read only
textBrowser->setReadOnly(true);
// Do not show frames
textBrowser->setFrameStyle(true);
textBrowser->setFrameStyle(QFrame::Plain);
// NOTE: That allows to open links from the html code
textBrowser->setOpenExternalLinks(true);
// Use layout
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(textBrowser);
setLayout(layout);
}
void MyWidget::setText(QString data)
{
// Set some html data into QTextBrowser
textBrowser->setHtml(data);
}
MyWidget::~MyWidget()
{
}
See also
- For more information about QTextBrowser, see QTextBrowser Class Reference.
Postconditions
QTextBrowser shows HTML and the device's web browser follows the link when the user selects it.


(no comments yet)