Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Using QTextBrowser in Qt

From Wiki
Jump to: navigation, search

Archived.pngArchived: 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.

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
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


Postconditions

QTextBrowser shows HTML and the device's web browser follows the link when the user selects it.

This page was last modified on 11 October 2012, at 01:15.
148 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×