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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Themed Views

Themed Views

Themed Views defined by XML files, describe a hierarchical group of visual and formatting elements. They are used by the following:

  • Title bar
  • Home screen
  • Call screen
  • Dialer
  • Context bar
  • Boot charger
  • Secondary Home screen (Optional)
  • Secondary Title bar (Optional)

to display items such as: status information, text and animations.

Qt Extended interacts with a themed view using elements such as page, line, alarm, date, button0. Each of these elements has attributes which affect the visual appearance and placement of elements. For a full list of view elements refer to: Themed View Elements. Attributes that are common to many elements are known as Common attributes and include:

  • Naming Elements
  • Positioning Elements
  • Showing/Hiding Elements
  • Specifying Colors
  • Alignment
  • Stretching Images
  • Interactive Elements.

The following sections provide detailed descriptions of these elements.

Naming Elements

The name attribute is available for all elements, however, each element within a type must have a unique name as Qt Extended interacts with elements using their name. For a list of Qt Extended elements see Known Elements.

Positioning Elements

The rect attribute is available for all elements and positions an element relative to the parent element geometry. It has one of two forms:

  1. x,y,wxh - specifies the top, left corner and the width and height.
  2. x1,y1,x2,y2 - specifies the top, left and bottom, right corners.

If any of the top or left coordinates are negative, they are relative to the right/bottom of the parent element. If bottom or right coordinates are less than or equal to zero, they are relative to the right/bottom of the parent element. This allows a theme to scale.

For example, to place a rect element that scales as the view gets wider:

    <rect rect="20,10,-20,50" color="Highlight" brush="Highlight"/>

This places a rectangle, using the Highlight color, at 20,10 with height of 40 pixels and the y2 coordinate 20 pixels from the parent element's right side.

Units

The theme engine supports different units. By default position and size are specified in pixels but it is possible to use point sizes or proportional positioning.

    <rect rect="10,10,150x12pt"/>

This element has a height of 12 points.

    <image src="settings" rect="0,0,50%x50%"/>

This element width and height are half of the width and height of its parent. It will be updated if the size of the parent changes.

Showing/Hiding Elements

Attributes to show or hide and elements are available to all elements. The transient and active attributes control the visibility of an element. Both the transient and active attributes can have literal values of yes or no, with the default value for transient being no and the default value of active being yes. The active attribute only has effect when transient="yes". In addition to a literal value, a boolean expression can also be specified for the value of the active attribute. This allows the visibility of a theme element to be controlled by the valuespace.

    <rect name="newmessages" transient="yes" active="expr:@/Communications/Messages/NewMessages > 0"/>

In the above example the "newmessages" rect element will only be active(visible) when the valuespace key /Communications/Messages/NewMessages returns a value > 0.

Specifying Colors

Colors can be specifed by either their hex color code of the form #RRGGBB, by their Qt QColorGroup color roles:

  • None - do not paint/blend with any color.
  • Background - general background color.
  • Foreground - general foreground color.
  • Base - used as background color for e.g. text entry widgets, usually white or another light color.
  • Text - the foreground color used with Base. Usually this is the same as the Foreground, in what case it must provide good contrast both with Background and Base.
  • Button - general button background color, where buttons need a background different from Background.
  • ButtonText - a foreground color used with the Button color.

There are some color roles used mostly for 3D bevel and shadow effects:

  • Light - lighter than Button color.
  • Midlight - between Button and Light.
  • Dark - darker than Button.
  • Mid - between Button and Dark.
  • Shadow - a very dark color.

All of these are normally derived from Background, and used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look good.

Selected (marked) items have two roles:

  • Highlight - a color to indicate a selected or highlighted item.
  • HighlightedText - a text color that contrasts to Highlight.

Finally, there is a special role for text that needs to be drawn where Text or Foreground would provide bad contrast, such as on pressed push buttons:

  • BrightText - a text color that is very different from Foreground and contrasts well with e.g. Dark.

Alignment

Some elements can be aligned by specifying:

  • left
  • hcenter
  • right
  • top
  • vcenter
  • bottom

To specify both horizontal and vertical alignment separate the alignment flags by a comma.

Stretching Images

Images and masks can be stretched to support themes that scale to different screen sizes. Stretching specifies a portion of the image that can be duplicated to fill the area between the start and end of the stretched image. The stretching can only be performed in one direction.

This illustration shows that the area bewteen point S1 and S2 is duplicated as necessary when the image is drawn. The stretch points are separated by a comma, e.g. stretch="16,48".

Interactive Elements

In order to allow feedback when elements are pressed on touch screen phones the interactive attribute can be set to "yes". This allows alternative attribute values to be defined when the element (and it's children) is clicked.

For example, the following code changes the graphic and text color when any element in the group is clicked (the group element ensures that clicking on any child affects all children).

    <group name="profile" rect="0,0,98x14" interactive="yes" transient="yes" active="no">
        <image name="profile" rect="0,0,98x14" src="profile" onclick="src=profile-pressed;color=Highlight"/>
        <text name="profile" size="10" rect="4,0,90x12" align="hcenter" onclick="color=HighlightedText"/>
    </group>

It is also possible to send a QCop message in the "onclick" attribute.

The syntax is:

    message=<Service Path>,<Service name>[,<Service parameters>]

where <Service parameters> is optional.

    <image rect="0,0,98x14" src="vibrate" onclick="message=QPE/System,toggleVibrate()"/>

Expressions and Valuespace

Some items can make use of expressions using QExpressionEvaluator, which ultimately means they can use the Qt Extended valuespace as input.

Expressions may be specified for the values of items themselves (eg. <element>expr:2+2</element>) or for values of the item's attributes (eg. <element attr="expr:2+2"/>). The 'expr:' indicates that the string is an expression and not a literal value. Everything after 'expr:' is assumed to be the expression data and is passed as-is to QExpressionEvaluator::setExpression(). You should consult the QExpressionEvaluator documentation to determine what you may legally pass.

Only certain items and attributes support expressions. Expressions are currently supported for:

Base valuespace paths for expressions can be specified using the vspath attribute. Whenever an expression is specified, any valuespace keys it contains will be considered relative to the item's base valuespace path. An item's base valuespace path is the sum of its own and its parents' vspath attributes. For example:

    <rect vspath="/Level1">
        <rect vspath="/Level2">
            <rect vspath="/Level3">
                <text>expr:@Text</text> <-- @Text expands to /Level1/Level2/Level3/Text
            </rect>
        </rect>
    </rect>

Templates

Templates allow an abstract 'visual look' to be declared in theme XML and then factorized and drawn to a custom user interface component.

Consider an example where we would like to theme the look of button. We can use templates to define the look of the button and then draw an instance of that look to the button.

First we define the template in Theme XML.

    <page vspath="/UIComponents">
        <template name="buttonnormal">
            <image rect="0,0,0,0" src="buttonnormalbg"/>
            <text rect="0,0,0,0" align="hcenter,vcenter">expr:@NormalText</text>
        </template>
        <template name="buttonclicked">
            <image rect="0,0,0,0" src="buttonclickedbg"/>
            <text rect="0,0,0,0" align="hcenter,vcenter">expr:@PressedText</text>
        </template>
    </page>

Then assuming the theme XML has been loaded into a ThemedView, we create a instance of the template and use it to draw our button.

    class ThemedButton : public QPushButton
    {
    private:
        ThemedView* view; // contains the loaded theme
        bool buttonPressed; // contains a flag indicating whether the button is currently pressed or not
    protected:
        void paintEvent(QPaintEvent* e)
        {
            // find our template
            QString templateName = buttonPressed ? "buttonnormal" : "buttonclicked";
            ThemeTemplateItem* template = (ThemeTemplateItem*)view->findItem(templateName, ThemedView::Template);
            Q_ASSERT(template != 0);

            // create an instance of the template
            ThemeTemplateInstanceItem* instance = template->createInstance(QString::number( (int)this )); // pass a uid to createInstace, used as value for vspath
            // paint the template instance to this widget
            QPainter p(this);
            view->paint(&p, e->rect(), instance);

            // cleaup
            delete instance;
        }
    };

The createInstance() line needs further explanation. The ThemeTemplateItem::createInstance() takes a unique identifier which is used as the vspath value for the template instance. This means each template has its own unique value space path for expressions to operate on. In this case the base valuespace path will be "/UIComponents/<uid>/" and so the text items in the template will refer to "/UIComponents/<uid>/NormalText" and "/UIComponents/<uid>/PressedText" where uid is in this case the this pointer of the class converted to a string.

Lists

Themed Views have the ability to display themed lists using QListView, theme expressions, templates and the Qt model/view. See the documentation of ThemeListModel for more details.

See also themetemplateelement and ThemeTemplateItem.

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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 48
  4. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 13
  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 Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

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 qtextended4.4
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