Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

[Prev: Reference: Windows] [Home]

Reference: The .ui File Format

Qt Designer stores forms in .ui files. These files use an XML format to represent form elements and their characteristics. This document provides an overview of the XML format used, and should provide enough information for developers to write their own .ui parsers so that they can read and modify .ui files programatically.

One way to parse a .ui file is to use Qt and the QDomDocument class; this is how Qt Designer does it: see the uilib/qwidgetfactory.h and uilib/qwidgetfactory.cpp source files. For information on dynamically loading and running .ui files see Loading and Executing a Dynamic Dialog.

The doctype of a .ui file is simply "UI", so the doctype tag is:


The root element is a "UI", which encloses the entire contents:

<UI version="3.1" stdsetdef="1">

Within the UI entity, there may one or zero of the following element types:

The ordering of elements is arbitrary, although it is common for the class element to be first.

UI Elements


This element is used to store the form's actions. It only occurs in QMainWindow forms.

The actions element contains one or more action elements. Each action element contains one or more properties. Each property has a name attribute, and a single value which is contained within a datatype element.

        <property name="name">
        <property name="iconSet">
        <property name="text">
        <property name="menuText">
        <property name="accel">


This element is used to store the author's name as a simple string.

<author>Barney Rubble</author>


This element is used to store the form's class name as a simple string.



This element is used to store comments, for example, copyright notices, as a simple string.

** Copyright (C) 2002 Trolltech ASA.  All rights reserved.
** This file is part of Qt Designer.
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Alternatively you may (at your option) use any
** later version of the GNU General Public License if such license has
** been publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free Qt Foundation.
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** If you are unsure which license is appropriate for your use, please
** review the following information:
** or contact the sales department at
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with
** the Software.
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.


This element is used to record the signals and slots connections in the form.

The connections element contains one or more connection elements and one or more slot elements. Each connection element identifies the signaling object and its signal, and the receiving object and its slot.

    <connection language="C++">


Qt Designer can operate with custom widgets. A custom widget is represented in a .ui file using the <customwidget> element.

Note that these are the 'old-style' custom widgets that show up on the form as grey rectangles. Use plugins to seamlessly integrate your custom widgets into Qt Designer -- see Creating Custom Widgets with Plugins.

Each custom widget has a class name and a header file. They also have a size hint and size policy. A pixmap can be specified; this is displayed on a Qt Designer toolbar button which the user can use to create an instance of the custom widget. Custom widgets usually emit signals, and these are listed. The name and type of any properties that the widget has are also included.

        <header location="local">styledbutton.h</header>
        <property type="Color">color</property>
        <property type="Pixmap">pixmap</property>
        <property type="Bool">scale</property>


This tag is only relevant to Windows users.

If you have a class that requires some Windows-specific export macro, e.g. for classes in a DLL that need to be declared like this: class win_specific_declaration_goes_here Class, you can use the <exportmacro> tag. (In standard Qt we use the Q_EXPORT macro, e.g. class Q_EXPORT QWidget.) If you use this tag you must also:

  1. include the file which contains the macro definition;

  2. add the export macro to the form -- this is achieved by entering the macro's name in the 'export macro' sub-property of the form's name property.

Following these steps will ensure that uic will create the correct class YOUR_MACRO Form declarations.



It is sometimes necessary to forward declare classes, particularly if code is being written in .ui.h files within Qt Designer. Each forward declaration is listed as it should appear in the generated C++ code.

    <forward>class QStringList;</forward>


The functions element contains a list of functions. Functions are standard C++ functions. It is possible to specify various attributes to create a function's signature, for example:

    <function access="private" specifier="non virtual">isValid()</function>
    <function access="public" returnType="QString">getMessage()</function>


Images are normally stored in their own files and associated with forms using project files. This has the advantage that images can be shared across any number of forms in a project, and between projects.

In some cases it may be desireable to store image data directly in a form, and the <image> tag allows for this.

It is possible to store images in both PNG and XPM formats, although in practice only XPM is recommended because of bugs in some PNG libraries. See the saveImageData function in resource.cpp to see how the image data is encoded.

    <image name="image0">
        <data format="XPM.GZ" length="409">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022630543251d2e253d856405bffcbc54105b19c856360003103711c6b53006ab440370316528264b4c198450c5808a94d1ed00aac214832b43124b544ec414d34b4c4c441103f11341120831309758313d0cf3b0840b7258d55a73010092c14eca</data>


It is sometimes necessary to #include header files in a .ui file. Header files may be 'local', i.e. relative to the project's directory, or 'global', i.e. part of Qt or the compilers standard libraries. Header files are declared in the implementation wherever possible, although sometimes it is necessary to declare them in the declaration (header) file.

Qt Designer automatically adds <include> tags for a .ui's .ui.h file.

    <include location="local" impldecl="in implementation">pixmapcollection.h</include>
    <include location="local" impldecl="in implementation">pixmapchooser.h</include>
    <include location="local" impldecl="in implementation">project.h</include>
    <include location="global" impldecl="in implementation">qfileinfo.h</include>
    <include location="global" impldecl="in implementation">qimage.h</include>
    <include location="global" impldecl="in declaration">qpixmap.h</include>
    <include location="local" impldecl="in implementation">pixmapcollectioneditor.ui.h</include>


Every form has a default spacing and margin size. These can be overridden on a case-by-case basis.

<layoutdefaults spacing="6" margin="11"/>

See also layoutfunctions.


Sometimes the spacing and margin values should be determined dynamically, e.g. to provide a common look in a windowmanager.

<layoutfunctions spacing="LayoutClass::spacing" margin="LayoutClass::margin"/>

The rules for determining margin and spacing values are these:

  1. If an integer value is specified for margin or spacing then the value is used.

  2. If no integer value is specified and a layout function is specified then the function is used.

  3. If no integer value or function is specified then the default value from layoutdefaults is used.


Applications that use QMainWindow often have a menubar. The menubar has a name property and one or more popup menu items. Each menu item has one or more actions and optionally separators.

    <property name="name">
    <item text="&amp;File" name="PopupMenu">
        <action name="fileSaveAction"/>
        <action name="fileExitAction"/>
    <item text="&amp;Help" name="PopupMenu_2">
        <action name="helpAboutAction"/>
        <action name="helpAboutQtAction"/>


Images are normally included by listing their filenames in project files. Images can also be included inline using the images tag. Another way of dealing with images is to specify a function name. This function will be called, with the name (or 'key') of the relevant image, and is responsible for loading the appropriate image. To specify such a function the <pixmapfunction> tag is used.



Most applications store their images as separate files listed in the application's project file. This can be signified by including the <pixmapinproject> tag.



All the signals are listed Within a <signals> tag.



The slots element contains a list of slots. Each slot element provides a slot's prototype.

    <slot access="public" specifier="virtual" language="C++" 
        returnType="void">changeAlignment(QAction* align)</slot>

For available attributes see functions.


Tabstops indicate the widgets that get the focus as the user tabs through the form. The <tabstops> tag contains a list of tabstops, in order, each of which holds the name of a widget.



Forms that have toolbars (dock windows) use the <toolbars> tag to hold the details. These forms are normally QMainWindows (or subclasses). Each toolbar has a dock attribute which identifies which dock window the toolbar initially belongs to. They also have both name and label properties. Each toolbar button is represented by an action. Toolbars can also hold other widgets, in which case the <toolbar> tag includes appropriate <widget> tags which give the class, name and any non-default property values for the relevant widget.

    <toolbar dock="2">
        <property name="name">
        <property name="label">
        <action name="fileNewAction"/>
        <action name="fileOpenAction"/>
        <action name="fileSaveAction"/>
        <action name="editUndoAction"/>
        <action name="editRedoAction"/>
        <action name="editCutAction"/>
        <action name="editCopyAction"/>
        <action name="editPasteAction"/>
    <toolbar dock="2">
        <property name="name">
        <property name="label">
        <action name="leftAlignAction"/>
        <action name="centerAlignAction"/>
        <action name="rightAlignAction"/>
        <action name="boldAction"/>
        <action name="italicAction"/>
        <action name="underlineAction"/>
        <widget class="QComboBox">
            <property name="name">
        <widget class="QSpinBox">
            <property name="name">
            <property name="minValue">
            <property name="value">


Module variables are held in the <variables> tag. Variable type names often include < and >, which must be stored as entities. It is also possible to specify the access type - either public, protected or private. Default is protected.

    <variable access="private">SettingsDialog * settings;</variable>
    <variable>QMap&lt;int, QString&gt; bookmarks;</variable>
    <variable>HelpWindow *browser;</variable>
    <variable>HelpDialog *helpDock;</variable>
    <variable>QGuardedPtr&lt;FindDialog&gt; findDialog;</variable>
    <variable>static QPtrList&lt;MainWindow&gt; *windows;</variable>


Widgets are used at multiple levels within a .ui file. The whole form itself is a widget, and it contains other widgets, usually within the context of layouts such as hboxes, vboxes and grids.

Below is an example of a complete .ui file. The form itself is a QWidget with various non-default properties set. This widget contains a single hbox, which also has some non-default properties, and which contains a single QTextBrowser widget.

<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<widget class="QWidget">
    <property name="name">
    <property name="geometry">
    <property name="caption">
        <property name="name">
        <property name="margin">
        <property name="spacing">
        <widget class="QTextBrowser">
            <property name="name">
            <property name="text">
                <string>This program installs Qt.</string>
<layoutdefaults spacing="6" margin="11"/>


This tag is included for Qt 3.x beta backwards compatibility, and should not be used. Use forwards instead.


This tag is included for Qt 2.x beta backwards compatibility, and should not be used. Use includes instead.


This tag is included for Qt 3.x beta backwards compatibility, and should not be used. Use variables instead.

Datatype Elements

Complex Datatype Elements


This element holds colors for user interface elements for each color group. For example:

    <color> ... Foreground    ... </color>
    <color> ... Button        ... </color>
    <color> ... Light         ... </color>
    <color> ... Midlight      ... </color>
    <color> ... Dark          ... </color>
    <color> ... Mid           ... </color>
    <color> ... Text          ... </color>
    <color> ... BrightText    ... </color>
    <color> ... ButtonText    ... </color>
    <color> ... Base          ... </color>
    <color> ... Background    ... </color>
    <color> ... Shadow        ... </color>
    <color> ... Highlight     ... </color>
    <color> ... HighlightText ... </color>

See color for the format of the <color> element.

Copyright © 2007 TrolltechTrademarks
Qt 3.3.8