
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3TextBrowser class provides a rich text browser with hypertext navigation.More...
| Header: | #include <Q3TextBrowser> |
| Inherits: | Q3TextEdit |
| Q3TextBrowser(QWidget * parent = 0, const char * name = 0) | |
| QString | source() const |
| virtual void | backward() |
| virtual void | forward() |
| virtual void | home() |
| virtual void | reload() |
| virtual void | setSource(const QString & name) |
| virtual void | setText(const QString & txt, const QString & context) |
| void | setText(const QString & txt) |
| void | anchorClicked(const QString & name, const QString & link) |
| void | backwardAvailable(bool available) |
| void | forwardAvailable(bool available) |
| void | highlighted(const QString & link) |
| void | linkClicked(const QString & link) |
| void | sourceChanged(const QString & src) |
| virtual void | keyPressEvent(QKeyEvent * e) |
TheQ3TextBrowser class provides a rich text browser with hypertext navigation.
This class extendsQ3TextEdit (in read-only mode), adding some navigation functionality so that users can follow links in hypertext documents. The contents ofQ3TextEdit is set withsetText(), butQ3TextBrowser has an additional function,setSource(), which makes it possible to set the text to a named document. The name is looked up in the text view's mime source factory. If a document name ends with an anchor (for example, "#anchor"), the text browser automatically scrolls to that position (usingscrollToAnchor()). When the user clicks on a hyperlink, the browser will callsetSource() itself, with the link'shref value as argument. You can track the current source by connetion to thesourceChanged() signal.
Q3TextBrowser providesbackward() andforward() slots which you can use to implement Back and Forward buttons. Thehome() slot sets the text to the very first document displayed. ThelinkClicked() signal is emitted when the user clicks a link.
By usingQ3TextEdit::setMimeSourceFactory() you can provide your own subclass ofQ3MimeSourceFactory. This makes it possible to access data from anywhere, for example from a network or from a database. SeeQ3MimeSourceFactory::data() for details.
If you intend using the mime factory to read the data directly from the file system, you may have to specify the encoding for the file extension you are using. For example:
mimeSourceFactory()->setExtensionType("qml","text/utf8");
This is to ensure that the factory is able to resolve the document names.
Q3TextBrowser interprets the tags it processes in accordance with the default style sheet. Change the style sheet withsetStyleSheet(); seeQStyleSheet for details.
If you want to provide your users with editable rich text useQ3TextEdit. If you want a text browser without hypertext navigation useQ3TextEdit, and useQ3TextEdit::setReadOnly() to disable editing. If you just need to display a small piece of rich text useQSimpleRichText orQLabel.
This property holds the name of the displayed document.
This is a an empty string if no document is displayed or if the source is unknown.
Setting this property uses themimeSourceFactory() to lookup the named document. 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 withsetText().
If you are using the filesystem access capabilities of the mime source factory, you must ensure that the factory knows about the encoding of specified files; otherwise no data will be available. The default factory handles a couple of common file extensions such as*.html and*.txt with reasonable defaults. SeeQ3MimeSourceFactory::data() for details.
Access functions:
| QString | source() const |
| virtual void | setSource(const QString & name) |
Constructs an emptyQ3TextBrowser calledname, with parentparent.
[signal]void Q3TextBrowser::anchorClicked(constQString & name, constQString & link)This signal is emitted when the user clicks an anchor. Thelink is the value of thehref i.e. the name of the target document. Thename is the name of the anchor.
See alsolinkClicked().
[virtual slot]void Q3TextBrowser::backward()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 alsoforward() andbackwardAvailable().
[signal]void Q3TextBrowser::backwardAvailable(bool available)This signal is emitted when the availability ofbackward() changes.available is false when the user is athome(); otherwise it is true.
[virtual slot]void Q3TextBrowser::forward()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 alsobackward() andforwardAvailable().
[signal]void Q3TextBrowser::forwardAvailable(bool available)This signal is emitted when the availability offorward() changes.available is true after the user navigatesbackward() and false when the user navigates or goesforward().
[signal]void Q3TextBrowser::highlighted(constQString & link)This signal is emitted when the user has selected but not activated a link in the document.link is the value of thehref i.e. the name of the target document.
[virtual slot]void Q3TextBrowser::home()Changes the document displayed to be the first document the browser displayed.
[virtual protected]void Q3TextBrowser::keyPressEvent(QKeyEvent * e)Reimplemented fromQWidget::keyPressEvent().
The evente is used to provide the following keyboard shortcuts:
[signal]void Q3TextBrowser::linkClicked(constQString & link)This signal is emitted when the user clicks a link. Thelink is the value of thehref i.e. the name of the target document.
Thelink will be the absolute location of the document, based on the value of the anchor's href tag and the current context of the document.
See alsoanchorClicked().
[virtual slot]void Q3TextBrowser::reload()Reloads the current set source.
[virtual slot]void Q3TextBrowser::setText(constQString & txt, constQString & context)Reimplemented fromQ3TextEdit::setText().
[slot]void Q3TextBrowser::setText(constQString & txt)This is an overloaded function.
Sets the text totxt.
[signal]void Q3TextBrowser::sourceChanged(constQString & src)This signal is emitted when the mime source has changed,src being the new source.
Source changes happen both programmatically when callingsetSource(),forward(), backword() orhome() or when the user clicks on links or presses the equivalent key sequences.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.