Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTextBrowser Class Reference
[QtGui module]

The QTextBrowser class provides a rich text browser with hypertext navigation. More...

#include <QTextBrowser>

Inherits QTextEdit.

Properties

Public Functions

Public Slots

  • 21 public slots inherited from QTextEdit
  • 17 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

Additional Inherited Members

  • 2 static public members inherited from QFrame
  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject

Detailed Description

The QTextBrowser class provides a rich text browser with hypertext navigation.

This class extends QTextEdit (in read-only mode), adding some navigation functionality so that users can follow links in hypertext documents. The contents of QTextEdit are set with setHtml() or setPlainText(), but QTextBrowser also implements the setSource() function, making it possible to set the text to a named document. The name is looked up in a list of search paths and in the directory of the current document factory. If a document name ends with an anchor (for example, "#anchor"), the text browser automatically scrolls to that position (using scrollToAnchor()). When the user clicks on a hyperlink, the browser will call setSource() itself with the link's href value as argument. You can track the current source by connecting to the sourceChanged() signal.

QTextBrowser provides backward() and forward() slots which you can use to implement Back and Forward buttons. The home() slot sets the text to the very first document displayed. The anchorClicked() signal is emitted when the user clicks an anchor. To override the default navigation behavior of the browser, call the setSource() function to supply new document text in a slot connected to this signal.

If you want to provide your users with editable rich text use QTextEdit. If you want a text browser without hypertext navigation use QTextEdit, and use QTextEdit::setReadOnly() to disable editing. If you just need to display a small piece of rich text use QLabel.

If you want to load documents stored in the Qt resource system use qrc as the scheme in the URL to load. For example, for the document resource path :/docs/index.html use qrc:/docs/index.html as the URL with setSource().

See also QTextEdit and QTextDocument.


Property Documentation

modified : const bool

This property holds whether the contents of the text browser have been modified.

readOnly : const bool

This property holds whether the text browser is read-only.

searchPaths : QStringList

This property holds the search paths used by the text browser to find supporting content.

QTextBrowser uses this list to locate images and documents.

Access functions:

  • QStringList searchPaths () const
  • void setSearchPaths ( const QStringList & paths )

source : QUrl

This property holds the name of the displayed document.

This is a an invalid url if no document is displayed or if the source is unknown.

When setting this property QTextBrowser tries to find a document with the specified name in the paths of the searchPaths property and directory of the current source, unless the value is an absolute file path. It also checks for optional anchors and scrolls the document accordingly

If the first tag in the document is <qt type=detail>, the document is displayed as a popup rather than as new document in the browser window itself. Otherwise, the document is displayed normally in the text browser with the text set to the contents of the named document with setHtml().

Access functions:

  • QUrl source () const
  • virtual void setSource ( const QUrl & name )

undoRedoEnabled : const bool

This property holds whether the text browser supports undo/redo operations.


Member Function Documentation

QTextBrowser::QTextBrowser ( QWidget * parent = 0 )

Constructs an empty QTextBrowser with parent parent.

void QTextBrowser::anchorClicked ( const QUrl & link )   [signal]

This signal is emitted when the user clicks an anchor. The URL referred to by the anchor is passed in link.

Note that the browser will automatically handle navigation to the location specified by link unless you call setSource() in a slot connected. This mechanism is used to override the default navigation features of the browser.

void QTextBrowser::backward ()   [virtual slot]

Changes the document displayed to the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.

See also forward() and backwardAvailable().

void QTextBrowser::backwardAvailable ( bool available )   [signal]

This signal is emitted when the availability of backward() changes. available is false when the user is at home(); otherwise it is true.

void QTextBrowser::forward ()   [virtual slot]

Changes the document displayed to the next document in the list of documents built by navigating links. Does nothing if there is no next document.

See also backward() and forwardAvailable().

void QTextBrowser::forwardAvailable ( bool available )   [signal]

This signal is emitted when the availability of forward() changes. available is true after the user navigates backward() and false when the user navigates or goes forward().

void QTextBrowser::highlighted ( const QUrl & link )   [signal]

This signal is emitted when the user has selected but not activated an anchor in the document. The URL referred to by the anchor is passed in link.

void QTextBrowser::highlighted ( const QString & link )   [signal]

This is an overloaded member function, provided for convenience.

Convenience signal that allows connecting to a slot that takes just a QString, like for example QStatusBar's message().

void QTextBrowser::home ()   [virtual slot]

Changes the document displayed to be the first document the browser displayed.

void QTextBrowser::keyPressEvent ( QKeyEvent * ev )   [virtual protected]

The event ev is used to provide the following keyboard shortcuts:

KeypressAction
Alt+Left Arrowbackward()
Alt+Right Arrowforward()
Alt+Up Arrowhome()

Reimplemented from QWidget.

QVariant QTextBrowser::loadResource ( int type, const QUrl & name )   [virtual]

This function is called when the document is loaded. The type indicates the type of resource to be loaded. For each image in the document, this function is called once.

The default implementation ignores type and tries to locate the resources by interpreting name as a file name. If it is not an absolute path it tries to find the file in the paths of the searchPaths property and in the same directory as the current source. On success, the result is a QVariant that stores a QByteArray with the contents of the file.

If you reimplement this function, you can return other QVariant types. The table below shows which variant types are supported depending on the resource type:

ResourceTypeQVariant::Type
QTextDocument::HtmlResourceQString or QByteArray
QTextDocument::ImageResourceQImage, QPixmap or QByteArray

Reimplemented from QTextEdit.

void QTextBrowser::reload ()   [virtual slot]

Reloads the current set source.

void QTextBrowser::sourceChanged ( const QUrl & src )   [signal]

This signal is emitted when the source has changed, src being the new source.

Source changes happen both programmatically when calling setSource(), forward(), backword() or home() or when the user clicks on links or presses the equivalent key sequences.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Developer Network au hasard

Logo

Livre blanc de l'outillage de Qt Quick

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.1
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web