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  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QStyleSheet Class Reference


A collection of styles for rich text rendering and a generator of tags. More...

#include <qstylesheet.h>

Inherits QObject.

List of all member functions.

Public Members

  • QStyleSheet ( QObject * parent=0, const char * name=0 ) 
  • virtual ~QStyleSheet () 
  • QStyleSheetItem* item ( const QString & name ) 
  • const QStyleSheetItem* item ( const QString & name ) const
  • void insert ( QStyleSheetItem * item ) (internal)
  • virtual QTextCustomItem* tag ( const QString & name, const QMap<QString, QString> & attr, const QString & context, const QMimeSourceFactory & factory, bool emptyTag = FALSE ) const
  • virtual void scaleFont ( QFont & font, int logicalSize ) const
  • virtual void error ( const QString & ) const

Static Public Members


Detailed Description

A collection of styles for rich text rendering and a generator of tags.

By creating QStyleSheetItem 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 QTextView or a QTextBrowser. But also QLabel, QWhatsThis and QMessageBox support it for now, with others likely to follow. With QSimpleRichText it is possible to use the rich text renderer for custom widgets as well.

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

The structuring tags are:

  • <qt>...</qt> - A Qt rich text document. It understands the following attributes
    • title - the caption of the document. This attribute is easily accessible with QTextView::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. It can be used to explain certain expressions more detailed in a few sentences. The 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="granit.xpm". The pixmap name will be resolved by a QMimeSourceFactory().
    • text - The default text color, for example text="red"
    • link - The link color, for example link="green"
  • <title>...</h1> - The title of the page, equivalent to <qt title="..." >.
  • <h1>...</h1> - A top-level heading.
  • <h2>...</h2> - A sub-level heading.
  • <h3>...</h3> - A sub-sub-level heading.
  • <p>...</p> - A left-aligned paragraph. Adjust the alignment with the align attribute. Possible values are left, right and center.
  • <center>...</center> - A centered paragraph.
  • <blockquote>...</blockquote> - An indented paragraph, useful for quotes.
  • <ul>...</ul> - An un-ordered list. You can also pass a type argument to define the bullet style. The default is type=disc, other types are circle and square.
  • <ol>...</ol> - 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>...</li> - A list item. This tag can only be used within the context of ol or ul.
  • <pre>...</pre> - For larger junks of code. Whitespaces in the contents are preserved. For small bits of code, use the inline-style code.

Anchors and links are done with a single tag:

  • <a>...</a> - An anchor or link. The reference target is defined in the href attribute of the tag as in <a href="target.qml">...</a>. You can also specify an additional anchor within the specified target document, for example <a href="target.qml#123">...</a>. If a is meant to be an anchor, the reference source is given in the name attribute.

The default character style bindings are:

  • <em>...</em> - Emphasized. As default, this is the same as <i>...</i> (Italic)
  • <strong>...</strong> - Strong. As default, this is the same as <bold>...</bold> (bold).
  • <i>...</i> - Italic font style.
  • <b>...</b> - Bold font style.
  • <u>...</u> - Underlined font style.
  • <big>...</big> - A larger font size.
  • <small>...</small> - A smaller font size.
  • <code>...</code> - Indicates Code. As default, this is the same as <tt>...</tt> (typewriter). For larger junks of code, use the block-tag pre.
  • <tt>...</tt> - Typewriter font style.
  • <font>...</font> - Customizes the font size, family and text color. The tag understands the following attributes:
    • color - the text color, for example color="red" or color="#FF0000".
    • size - the logical size of the font. Logical sizes 1 to 7 are supported. The value may either be absolute, for example size=3, or relative like size=-2. In the latter case, the sizes are simply added.
    • face - the family of the font, for example face=times.

Special elements are:

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

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

  • <hr/> - A horizontal line
  • <br/> - A line break

Other tags not in any of the above categories are:

  • <nobr>...</nobr> - No break. Prevents word wrap.

In addition, rich text supports simple HTML tables. A table consists of a set of rows where each row contains some number of cells. Cells are either data cells or header cells, depending on their content. Usually a cell fills one rectangle in the table grid. It may, however, also span several rows, columns or both.

  • <table>...</table> - A table definition. The default table is frameless. Specify the boolean attribute border in order to get a frame. Other attributes are:
    • bgcolor - The background color
    • width - The table width. This is either absolute in pixels or relative in percent of the column width, for example width=80%
    • border - The width of the table border. The default is 0 (= no border).
    • cellspacing - Additional space around the table cells. The default is 2.
    • cellpadding - Additinal space around the contents of table cells. Default is 1.
  • <tr>...</tr> - A table row. Can only be used within table. Understands the attribute
    • bgcolor - The background color
  • <td>...</td> - A table data cell. Can only be used within tr. Understands the attributes
    • bgcolor - The background color
    • width - The cell width. This is either absolute in pixels or relative in percent of the entire table width, for example width=50%
    • colspan - Defines how many columns this cell spans. The default is 1.
    • rowspan - Defines how many rows this cell spans. The default is 1.
    • align - Alignment, possible values are left, right and center. The default is left-aligned.
  • <th>...</th> - A table header cell. Like td but defaults to center-alignment and a bold font.

Member Function Documentation

QStyleSheet::QStyleSheet ( QObject * parent=0, const char * name=0 )

Create a style sheet. Like any QObject, the created object will be deleted when its parent destructs (if the child still exists then).

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

QStyleSheet::~QStyleSheet () [virtual]

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

QString QStyleSheet::convertFromPlainText ( const QString & plain ) [static]

Auxiliary function. Converts the plain text string plain to a rich text formatted string while preserving its look.

QStyleSheet* QStyleSheet::defaultSheet () [static]

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

See also setDefaultSheet().

void QStyleSheet::error ( const QString & msg ) const [virtual]

This virtual function is called when an error occurs when processing rich text. Reimplement if 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 wrongly or if tags are not closed properly.

msg is the error message.

QStyleSheetItem* QStyleSheet::item ( const QString & name )

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

const QStyleSheetItem* QStyleSheet::item ( const QString & name ) const

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

bool QStyleSheet::mightBeRichText ( const QString & text ) [static]

Returns whether the string text is likely to be rich text formatted.

Note: The function uses a fast and therefore simple heuristic. It mainly checks whether there is something that looks like a tag before the first line break. While the result may be correct for most common cases, there is no guarantee.

void QStyleSheet::scaleFont ( QFont & font, int logicalSize ) const [virtual]

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.

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

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

void QStyleSheet::setDefaultSheet ( QStyleSheet * sheet ) [static]

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

See also defaultSheet().

QTextCustomItem* QStyleSheet::tag ( const QString & name, const QMap<QString, QString> & attr, const QString & context, const QMimeSourceFactory & factory, bool = FALSE ) const [virtual]

Generates an internal object for tag named name, given the attributes attr, and using additional information provided by the mime source factory factory .

This function should not (yet) be used in application code.

void QStyleSheet::insert ( QStyleSheetItem * style )

For internal use only.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  2. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  6. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
  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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 51
  4. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Quarterly au hasard

Logo

Utilisation du framework d'Undo/Redo avec les vues

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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 2.3
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