Qt:Документация 4.3.2/q3stylesheet

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] Q3StyleSheet Class Reference
[ Qt3Support module]

The Q3StyleSheet class is a collection of styles for rich text rendering and a generator of tags. Далее...

 #include <Q3StyleSheet>

This class is part of the Qt 3 support library. It is provided to keep old source code working. Мы настоятельно не рекомендуем использовать этот класс в новом коде. See Porting to Qt 4 for more information.

Inherits QObject.

[править] Открытые функции

  • Q3StyleSheet ( QObject * parent = 0, const char * name = 0 )
  • virtual ~Q3StyleSheet ()
  • virtual void error ( const QString & msg ) const
  • Q3StyleSheetItem * item ( const QString & name )
  • const Q3StyleSheetItem * item ( const QString & name ) const
  • virtual void scaleFont ( QFont & font, int logicalSize ) const
  • 29 открытых функций, унаследованных от QObject

[править] Статические открытые члены

  • 5 статических открытых членов, унаследованных от QObject

[править] Дополнительные унаследованные члены

  • 1 свойство, унаследованное от QObject
  • 1 открытый слот, унаследованный от QObject
  • 1 сигнал, унаследованный от QObject
  • 7 защищенных функций, унаследованных от QObject

[править] Подробное описание

The Q3StyleSheet class is a collection of styles for rich text rendering and a generator of tags.

By creating Q3StyleSheetItem objects for a style sheet you build a definition of a set of tags. This definition will be used by the internal rich text rendering system to parse and display text documents to which the style sheet applies. Rich text is normally visualized in a QTextEdit or a QTextBrowser. However, QLabel, QWhatsThis and QMessageBox also support it, and other classes are likely to follow. With QSimpleRichText it is possible to use the rich text renderer for custom widgets as well.

The default Q3StyleSheet object has the following style bindings, sorted by structuring bindings, anchors, character style bindings (i.e. inline styles), special elements such as horizontal lines or images, and other tags. In addition, rich text supports simple HTML tables.

The structuring tags are


Structuring tags Notes
<qt>...</qt> A Qt rich text document. It understands the following attributes:
  • title -- The caption of the document. This attribute is easily accessible with QTextEdit::documentTitle().
  • type -- The type of the document. The default type is page. It indicates that the document is displayed in a page of its own. Another style is detail, which can be used to explain certain expressions in more detail in a few sentences. For detail, QTextBrowser will then keep the current page and display the new document in a small popup similar to QWhatsThis. Note that links will not work in documents with <qt type="detail">...</qt>.
  • bgcolor -- The background color, for example bgcolor="yellow" or bgcolor="#0000FF".
  • background -- The background pixmap, for example background="granite.xpm". The pixmap name will be resolved by a Q3MimeSourceFactory().
  • text -- The default text color, for example text="red".
  • link -- The link color, for example link="green".

...

A top-level heading.

...

A sublevel heading.

...

A sub-sublevel heading.

...

A left-aligned paragraph. Adjust the alignment with the align attribute. Possible values are left, right and center.
...</tt>
<tt>
A centered paragraph.
...</tt>
<tt>
An indented paragraph that is useful for quotes.
    ...
An unordered list. You can also pass a type argument to define the bullet style. The default is type=disc; other types are circle and square.
    ...
An ordered list. You can also pass a type argument to define the enumeration label style. The default is type="1"; other types are "a" and "A".
  • ...</li>
  • A list item. This tag can be used only within the context of
      </tt> or <tt>
        </tt>.
    <tt>
    ...
    </tt>
    For larger chunks of code. Whitespaces in the contents are preserved. For small bits of code use the inline-style <tt>code</tt>.

    Anchors and links are done with a single tag:


    Anchor tags Notes
    <tt><a>...</a></tt> An anchor or link.
    • A link is created by using an <tt>href</tt> attribute, for example
      <tt><a href="target.qml">Link Text</a></tt>. Links to targets within a document are achieved in the same way as for HTML, e.g.
      <tt><a href="target.qml#subtitle">Link Text</a></tt>.
    • A target is created by using a <tt>name</tt> attribute, for example
      <tt><a name="subtitle">

      Sub Title

      </a></tt>.

    The default character style bindings are


    Style tags Notes
    <tt>...</tt> Emphasized. By default this is the same as <tt>...</tt> (italic).
    <tt>...</tt> Strong. By default this is the same as <tt>...</tt> (bold).
    <tt>...</tt> Italic font style.
    <tt>...</tt> Bold font style.
    <tt>...</tt> Underlined font style.
    <tt>...</tt> Strike out font style.
    <tt>...</tt> A larger font size.
    <tt>...</tt> A smaller font size.
    <tt>...</tt> Subscripted text
    <tt>...</tt> Superscripted text
    <tt>...</tt> Indicates code. By default this is the same as <tt><tt>...</tt></tt> (typewriter). For larger chunks of code use the block-tag <tt><</tt><tt>pre></tt>.
    <tt><tt>...</tt></tt> Typewriter font style.
    <tt>...</tt> Customizes the font size, family and text color. The tag understands the following attributes:
    • <tt>color</tt> -- The text color, for example <tt>color="red"</tt> or <tt>color="#FF0000"</tt>.
    • <tt>size</tt> -- The logical size of the font. Logical sizes 1 to 7 are supported. The value may either be absolute (for example, <tt>size=3</tt>) or relative (<tt>size=-2</tt>). In the latter case the sizes are simply added.
    • <tt>face</tt> -- The family of the font, for example <tt>face=times</tt>.

    Special elements are:


    Special tags Notes
    <tt><img></tt> An image. The image name for the mime source factory is given in the source attribute, for example <tt><img src="qt.xpm"></tt> The image tag also understands the attributes <tt>width</tt> and <tt>height</tt> that determine the size of the image. If the pixmap does not fit the specified size it will be scaled automatically (by using QImage::smoothScale()).

    The <tt>align</tt> attribute determines where the image is placed. By default, an image is placed inline just like a normal character. Specify <tt>left</tt> or <tt>right</tt> to place the image at the respective side.

    <tt>
    </tt>
    A horizontal line.
    <tt>
    </tt>
    A line break.
    <tt><nobr>...</nobr></tt> No break. Prevents word wrap.

    In addition, rich text supports simple HTML tables. A table consists of one or more rows each of which contains one or more cells. Cells are either data cells or header cells, depending on their content. Cells which span rows and columns are supported.


    Table tags Notes
    <tt>...
    </tt>
    A table. Tables support the following attributes:
    • <tt>bgcolor</tt> -- The background color.
    • <tt>width</tt> -- The table width. This is either an absolute pixel width or a relative percentage of the table's width, for example <tt>width=80%</tt>.
    • <tt>border</tt> -- The width of the table border. The default is 0 (= no border).
    • <tt>cellspacing</tt> -- Additional space around the table cells. The default is 2.
    • <tt>cellpadding</tt> -- Additional space around the contents of table cells. The default is 1.
    <tt><tr>...</tr></tt> A table row. This is only valid within a <tt>table</tt>. Rows support the following attribute:
    • <tt>bgcolor</tt> -- The background color.
    <tt><th>...</th></tt> A table header cell. Similar to <tt>td</tt>, but defaults to center alignment and a bold font.
    <tt><td>...</td></tt> A table data cell. This is only valid within a <tt>tr</tt>. Cells support the following attributes:
    • <tt>bgcolor</tt> -- The background color.
    • <tt>width</tt> -- The cell width. This is either an absolute pixel width or a relative percentage of table's width, for example <tt>width=50%</tt>.
    • <tt>colspan</tt> -- Specifies how many columns this cell spans. The default is 1.
    • <tt>rowspan</tt> -- Specifies how many rows this cell spans. The default is 1.
    • <tt>align</tt> -- Qt::Alignment; possible values are <tt>left</tt>, <tt>right</tt>, and <tt>center</tt>. The default is <tt>left</tt>.
    • <tt>valign</tt> -- Qt::Vertical alignment; possible values are <tt>top</tt>, <tt>middle</tt>, and <tt>bottom</tt>. The default is <tt>middle</tt>.

    [править] Описание функций-членов

    [править]
    Q3StyleSheet::Q3StyleSheet ( QObject * parent = 0, const char * name = 0 )

    Creates a style sheet called name, with parent parent. Like any QObject it will be deleted when its parent is destroyed (if the child still exists).

    By default the style sheet has the tag definitions defined above.

    [править]
    Q3StyleSheet::~Q3StyleSheet () <tt> [virtual]</tt>

    Destroys the style sheet. All styles inserted into the style sheet will be deleted.

    [править]
    QString Q3StyleSheet::convertFromPlainText ( const QString & plain, Q3StyleSheetItem::WhiteSpaceMode mode = Q3StyleSheetItem::WhiteSpacePre ) <tt> [static]</tt>

    Вспомогательная функция. Конвертирует простую текстовую строку plain в параграф форматированного текста при сохранении большинства ее вида.

    mode определяет whitespace mode. Possible values are <tt>Q3StyleSheetItem::WhiteSpacePre</tt> (no wrapping, all whitespaces preserved) and Q3StyleSheetItem::WhiteSpaceNormal (wrapping, simplified whitespaces).

    См. также escape().

    [править]
    Q3StyleSheet * Q3StyleSheet::defaultSheet () <tt> [static]</tt>

    Returns the application-wide default style sheet. This style sheet is used by rich text rendering classes such as QSimpleRichText, QWhatsThis and QMessageBox to define the rendering style and available tags within rich text documents. It also serves as the initial style sheet for the more complex render widgets, QTextEdit and QTextBrowser.

    See also setDefaultSheet().

    [править]
    void Q3StyleSheet::error ( const QString & msg ) const <tt> [virtual]</tt>

    This virtual function is called when an error occurs when processing rich text. Reimplement it if you need to catch error messages.

    Errors might occur if some rich text strings contain tags that are not understood by the stylesheet, if some tags are nested incorrectly, or if tags are not closed properly.

    msg is the error message.

    [править]
    QString Q3StyleSheet::escape ( const QString & plain ) <tt> [static]</tt>

    Вспомогательная функция. Конвертирует простую текстовую строку plain в параграф форматированного текста с экранированием любых HTML мета-символов.

    See also convertFromPlainText().

    [править]
    Q3StyleSheetItem * Q3StyleSheet::item ( const QString & name )

    Returns the style called name or 0 if there is no such style.

    [править]
    const Q3StyleSheetItem * Q3StyleSheet::item ( const QString & name ) const

    Эта перегруженная функция предоставлена для удобства.

    Returns the style called name or 0 if there is no such style (const version)

    [править]
    bool Q3StyleSheet::mightBeRichText ( const QString & text ) <tt> [static]</tt>

    Возвращает истину если строка text подобна форматированному тексту; в противном случае ложь.

    Эта функция использует простой и поэтому быстрый эвристический способ анализа. Она, главным образом, проверяет, есть ли что-либо, что напоминает признаки форматирования до первого разрыва строки. Хотя для большинства случаев результат может быть правилен, никакой гарантии не дается.

    [править]
    void Q3StyleSheet::scaleFont ( QFont & font, int logicalSize ) const <tt> [virtual]</tt>

    Scales the font font to the appropriate physical point size corresponding to the logical font size logicalSize.

    When calling this function, font has a point size corresponding to the logical font size 3.

    Logical font sizes range from 1 to 7, with 1 being the smallest.

    See also Q3StyleSheetItem::logicalFontSize(), Q3StyleSheetItem::logicalFontSizeStep(), and QFont::setPointSize().

    [править]
    void Q3StyleSheet::setDefaultSheet ( Q3StyleSheet * sheet ) <tt> [static]</tt>

    Sets the application-wide default style sheet to sheet, deleting any style sheet previously set. The ownership is transferred to Q3StyleSheet.

    See also defaultSheet().



    Copyright © 2007 Trolltech Trademarks
    Qt 4.3.2