![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QTextView class provides a sophisticated rich text viewer. More...
#include <qtextview.h>
Inherits QScrollView.
Inherited by QTextEdit and QTextBrowser.
QTextView is a widget which can show large amounts of uneditable text with varying fonts and font attributes, e.g. different point sizes, colors, bold, italic, etc. Paragraphs can have different alignments and word-wrap policies. QTextView can also show images (using QMimeSourceFactory), lists and tables. If the text is too large to view within the text view's viewport, scrollbars will appear. The text view can load both plain text and HTML files (a subset of HTML 4 and CSS1 is supported). The rendering style and valid tags are defined by a styleSheet(). Currently a subset of HTML 3.2 and 4, and CSS1 is supported, see setStyleSheet() and QStyleSheet for details. The images identified by image tags are displayed if they can be interpreted using the text view's QMimeSourceFactory. (See setMimeSourceFactory() for details.)
If you want to provide your users with editable rich text use QTextEdit. If you want a text browser with more navigation use QTextBrowser. If you just need to display a small piece of rich text use QLabel or QSimpleRichText.
Set the text with setText(). You can include rich text directly in your source code since it is based on HTML tags, e.g.
textView->setText( "<font color=\"red\">Red</font>" );You can append text with append(), for example to display an output log.
By default the text view will try to guess the format of the text (plain text or HTML) and display accordingly, but you can control this with setTextFormat().
By default the text view wraps words at whitespace to fit within the text view widget. The setWordWrap() function is used to specify the kind of word wrap you want, or NoWrap if you don't want any wrapping. Call setWordWrap() to set a fixed pixel width FixedPixelWidth, or character column (e.g. 80 column) FixedColumnWidth with the pixels or columns specified with setWrapColumnOrWidth(). If you use word wrap to the widget's width WidgetWidth, you can specify whether to break on whitespace or anywhere with setWrapPolicy().
The background color is set differently than other widgets, using setPaper(). You specify a brush style which could be a plain color or a complex pixmap. Hypertext links are automatically underlined; this can be changed with setLinkUnderline(). The tab stop width is set with setTabStopWidth(). The zoomIn() and zoomOut() functions can be used to resize the text by increasing (decreasing for zoomOut()) the point size by one point per call. Images are not affected.
The entire text is returned by text(), and the text of a particular paragraph by text(int).
The user can select text in the text view using the mouse. If they've selected text hasSelectedText() will return TRUE. The selection's position can be obtained with getSelection(), and the selection itself is returned by selectedText(). The selection can be copied to the clipboard with copy(). The entire text can be selected (or deselected) with selectAll().
The lines() function returns the number of lines in the text, paragraphs() returns the number of paragraphs. The number of lines within a particular paragraph is returned by linesOfParagraph(). The length of the entire text in characters is returned by length().
You can scroll to an anchor in the text, e.g. <a name="anchor"> with scrollToAnchor(). The find() function can be used to find and select a given string within the text.
The user can navigate the text view by using the scrollbars and by clicking hypertext links with the mouse. The following keyboard shortcuts are also supported:
The text view may be able to provide some meta-information. The documentTitle() function will return the text from within HTML <title> tags.
The text displayed in a text view has a context. The context is a path which the text view's QMimeSourceFactory uses to resolve the locations of files and images. It is passed to the mimeSourceFactory() when quering data. (See QTextView() and context().)
Note that we do not intend to add a full-featured web browser widget to Qt (because that would easily double Qt's size and only a few applications would benefit from it). In particular, the rich text support in Qt is designed to provide a fast, portable and efficient way to add reasonable online help facilities to applications.
This enum defines the QTextView's word wrap modes. The following values are valid:
See also wordWrap and wordWrap.
This enum defines where text can be wrapped in word wrap mode.
The following values are valid:
See also wrapPolicy.
The context is a path which the text view's QMimeSourceFactory uses to resolve the locations of files and images. It is passed to the mimeSourceFactory() when quering data.
For example if the text contains an image tag, <img src="image.png">, and the context is "path/to/look/in", the QMimeSourceFactory will try to load the image from "path/to/look/in/image.png". If the tag was <img src="/image.png">, the context will not be used (because QMimeSourceFactory recognizes that we have given an absolute path) and will try to load "/image.png". The context is applied in exactly the same way to hrefs, for example, <a href="target.html">Target</a>, would resolve to "path/to/look/in/target.html".
Examples: clientserver/client/client.cpp, clientserver/server/server.cpp, httpd/httpd.cpp, mdi/application.cpp and process/process.cpp.
The context is a path which the text view's QMimeSourceFactory uses to resolve the locations of files and images.
Examples: helpviewer/helpwindow.cpp and qdir/qdir.cpp.
See also hasSelectedText and copyAvailable().
This signal is emitted when text is selected or deselected in the text view.
When text is selected this signal will be emitted with yes set to TRUE. If no text has been selected or if the selected text is deselected this signal is emitted with yes set to FALSE.
If yes is TRUE then copy() can be used to copy the selection to the clipboard. If yes is FALSE then copy() does nothing.
See also selectionChanged().
This function returns the QTextDocument which is used by the text view.
QTextDocument is not in the public API and its API might change in an incompatible manner in the future.
Returns the title of the document parsef from the text. See the "documentTitle" property for details.
If para and index are both 0 the search begins from the start of the text. If cs is TRUE the search is case sensitive, otherwise it is case insensitive. If wo is TRUE the search looks for whole word matches only; otherwise it searches for any matching text. If forward is TRUE (the default) the search works forward from the starting position to the end of the text, otherwise it works backwards to the beginning of the text.
If expr is found the function returns TRUE and overwrites para with the number of the paragraph in which the first character of the match was found and index with the index position of that character within the para.
If expr is not found the function returns FALSE and the contents of index and para are undefined.
Reimplemented from QScrollView.
If there is no selection, paraFrom, indexFrom, paraTo and indexTo are all set to -1.
The selNum is the number of the selection (since multiple selections are supported). It defaults to 0 (the first selection).
See also selectedText.
Returns TRUE whether some text is selected, otherwise returns FALSE. See the "hasSelectedText" property for details.
Reimplemented from QWidget.
Reimplemented from QWidget.
Reimplemented in QTextBrowser.
Returns the total number of characters in the text. See the "length" property for details.
WARNING: This function may be slow. Lines change all the time during word wrapping, so this function has to iterate over all the paragraphs and get the number of lines from each one individually.
Examples: action/application.cpp and application/application.cpp.
Returns TRUE whether links will be underlined, otherwise returns FALSE. See the "linkUnderline" property for details.
See also setMimeSourceFactory().
Examples: helpviewer/helpwindow.cpp and qdir/qdir.cpp.
Returns the background (paper) brush. See the "paper" property for details.
Although used extensively internally you shouldn't need to call it yourself.
Returns the selected text or an empty string if there is no currently selected text. See the "selectedText" property for details.
This signal is emitted whenever the selection changes.
See also copyAvailable().
This function sets the QTextDocument which should be used by the text view. This can be used, for example, if you want to display a document using multiple views. You would create a QTextDocument and set it to the text views which should display it. You would need to connect to the textChanged() and selectionChanged() signals of all the text views and update them all accordingly (preferably with a slight delay for efficiency reasons).
QTextDocument is not in the public API and its API might change in an incompatible manner in the future.
Sets whether links will be underlined. See the "linkUnderline" property for details.
See also mimeSourceFactory().
Sets the background (paper) brush to pap. See the "paper" property for details.
See also styleSheet().
See also tabStopWidth().
Sets the text view's text to txt. See the "text" property for details.
Changes the text of the view to the string text and the context to context. Any previous text is removed.
text may be interpreted either as plain text or as rich text, depending on the textFormat(). The default setting is AutoText, i.e. the text view autodetects the format from text.
The optional context is a path which the text view's QMimeSourceFactory uses to resolve the locations of files and images. (See QTextView::QTextView().) It is passed to the text view's QMimeSourceFactory when quering data.
See also text and textFormat.
Sets the text format: rich text, plain text or auto text to f. See the "textFormat" property for details.
Sets the word wrap mode to mode. See the "wordWrap" property for details.
Sets the position (in pixels or columns depending on the wrap mode) where text will be wrapped. See the "wrapColumnOrWidth" property for details.
Sets the word wrap policy, at whitespace or anywhere to policy. See the "wrapPolicy" property for details.
See also setStyleSheet().
Example: helpviewer/helpwindow.cpp.
See also setTabStopWidth().
Returns the text view's text. See the "text" property for details.
If textFormat() is RichText the text will contain HTML formatting tags.
This signal is emitted whenever the text in the text view changes.
Examples: helpviewer/helpwindow.cpp, qwerty/qwerty.cpp and rot13/rot13.cpp.
Returns the text format: rich text, plain text or auto text. See the "textFormat" property for details.
Returns the word wrap mode. See the "wordWrap" property for details.
Returns the position (in pixels or columns depending on the wrap mode) where text will be wrapped. See the "wrapColumnOrWidth" property for details.
Returns the word wrap policy, at whitespace or anywhere. See the "wrapPolicy" property for details.
See also zoomOut().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Zooms in on the text by by making the standard font size one point larger and recalculating all font sizes. This does not change the size of any images.
See also zoomOut().
See also zoomIn().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Zooms out on the text by by making the standard font size one point smaller and recalculating all font sizes. This does not change the size of any images.
See also zoomIn().
This property holds the title of the document parsef from the text.
For PlainText the title will be an empty string. For RichText the title will be the text between the <title> tags, if present, otherwise an empty string.
Get this property's value with documentTitle().
This property holds whether some text is selected.
Get this property's value with hasSelectedText().
This property holds the total number of characters in the text.
Returns the total number of characters of the text.
Get this property's value with length().
This property holds whether links will be underlined.
If TRUE links will be displayed underlined. If FALSE links will not be displayed underlined.
Set this property's value with setLinkUnderline() and get this property's value with linkUnderline().
This property holds the background (paper) brush.
The brush that is currently used to draw the background of the text view. The initial setting is an empty brush.
Set this property's value with setPaper() and get this property's value with paper().
This property holds the selected text or an empty string if there is no currently selected text.
The text is always returned as PlainText regardless of the text format. In a future version of Qt an HTML subset may be returned depending on the text format.
Get this property's value with selectedText().
See also hasSelectedText.
This property holds the text view's text.
The current text in the text view.
On setting, any previous text is deleted.
The value may be interpreted either as plain text or as rich text, depending on the textFormat(). The default setting is AutoText, i.e. the text view autodetects the format of the text.
Set this property's value with setText() and get this property's value with text().
See also textFormat.
This property holds the text format: rich text, plain text or auto text.
The current text format.
Possible values are:
Set this property's value with setTextFormat() and get this property's value with textFormat().
This property holds the word wrap mode.
The default mode is WidgetWidth which causes words to be wrapped at the right edge of the text view. Wrapping occurs at spaces, keeping whole words intact. If you want wrapping to occur within words use wrapPolicy. If you set a wrap mode of FixedPixelWidth or FixedColumnWidth you should also set wrapColumnOrWidth to the width you want.
Set this property's value with setWordWrap() and get this property's value with wordWrap().
See also QTextView::WordWrap, wrapColumnOrWidth and wrapPolicy.
This property holds the position (in pixels or columns depending on the wrap mode) where text will be wrapped.
If the wrap mode is FixedPixelWidth, the value is the number of pixels from the left edge of the text view at which text should be wrapped. If the wrap mode is FixedColumnWidth, the value is the column number (in character columns) from the left edge of the text view at which text should be wrapped.
Set this property's value with setWrapColumnOrWidth() and get this property's value with wrapColumnOrWidth().
See also wordWrap.
This property holds the word wrap policy, at whitespace or anywhere.
Defines where text can be wrapped when word wrap mode is not NoWrap. The choices are AtWhiteSpace (the default) and Anywhere.
Set this property's value with setWrapPolicy() and get this property's value with wrapPolicy().
See also wordWrap.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version main-beta1
|