Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/doc/src/development/designer-manual.qdoc

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    77** This file is part of the documentation of the Qt Toolkit.
    88**
    9 ** $QT_BEGIN_LICENSE:LGPL$
     9** $QT_BEGIN_LICENSE:FDL$
    1010** Commercial Usage
    1111** Licensees holding valid Qt Commercial licenses may use this file in
    1212** accordance with the Qt Commercial License Agreement provided with the
    13 ** Software or, alternatively, in accordance with the terms contained in
    14 ** a written agreement between you and Nokia.
     13** Software or, alternatively, in accordance with the terms contained in a
     14** written agreement between you and Nokia.
    1515**
    16 ** GNU Lesser General Public License Usage
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
    18 ** General Public License version 2.1 as published by the Free Software
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
    20 ** packaging of this file.  Please review the following information to
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    23 **
    24 ** In addition, as a special exception, Nokia gives you certain additional
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27 **
    28 ** GNU General Public License Usage
    29 ** Alternatively, this file may be used under the terms of the GNU
    30 ** General Public License version 3.0 as published by the Free Software
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
    32 ** packaging of this file.  Please review the following information to
    33 ** ensure the GNU General Public License version 3.0 requirements will be
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
     16** GNU Free Documentation License
     17** Alternatively, this file may be used under the terms of the GNU Free
     18** Documentation License version 1.3 as published by the Free Software
     19** Foundation and appearing in the file included in the packaging of this
     20** file.
    3521**
    3622** If you have questions regarding the use of this file, please contact
     
    17841770    \title Using a Designer UI File in Your Application
    17851771
    1786     With Qt's integrated build tools, \l{qmake Manual}{qmake} and \l uic, the
    1787     code for user interface components created with \QD is automatically
    1788     generated when the rest of your application is built. Forms can be included
    1789     and used directly from your application. Alternatively, you can use them to
    1790     extend subclasses of standard widgets. These forms can be processed at
    1791     compile time or at run time, depending on the approach used.
    1792 
     1772    Qt Designer UI files represent the widget tree of the form in XML format. The
     1773    forms can be processed:
     1774
     1775    \list
     1776        \o \l{Compile Time Form Processing}{At compile time}, which means that forms
     1777            are converted to C++ code that can be compiled.
     1778        \o \l{Run Time Form Processing}{At runtime}, which means that forms are processed
     1779            by the QUiLoader class that dynamically constructs the widget tree while
     1780            parsing the XML file.
     1781    \endlist
    17931782
    17941783    \tableofcontents
    17951784    \section1 Compile Time Form Processing
    17961785
     1786    You create user interface components with \QD and use Qt's integrated build tools,
     1787    \l{qmake Manual}{qmake} and \l{User Interface Compiler (uic)}{uic}, to generate code
     1788    for them when the application is built. The generated code contains the form's user
     1789    interface object. It is a C++ struct that contains:
     1790
     1791    \list
     1792        \o Pointers to the form's widgets, layouts, layout items,
     1793           button groups, and actions.
     1794        \o A member function called \c setupUi() to build the widget tree
     1795           on the parent widget.
     1796        \o A member function called \c retranslateUi() that handles the
     1797           translation of the string properties of the form. For more information,
     1798           see \l{Reacting to Language Changes}.
     1799    \endlist
     1800
     1801    The generated code can be included in your application and used directly from
     1802    it. Alternatively, you can use it to extend subclasses of standard widgets.
     1803
    17971804    A compile time processed form can be used in your application with one of
    17981805    the following approaches:
    17991806
    18001807    \list
    1801         \o  The Direct Approach: you construct a widget to use as a placeholder
     1808        \o  \l{The Direct Approach}: you construct a widget to use as a placeholder
    18021809            for the component, and set up the user interface inside it.
    1803         \o  The Single Inheritance Approach: you subclass the form's base class
     1810        \o  \l{The Single Inheritance Approach}: you subclass the form's base class
    18041811            (QWidget or QDialog, for example), and include a private instance
    18051812            of the form's user interface object.
    1806         \o  The MultipleInheritance Approach: you subclass both the form's base
     1813        \o  \l{The Multiple Inheritance Approach}: you subclass both the form's base
    18071814            class and the form's user interface object. This allows the widgets
    18081815            defined in the form to be used directly from within the scope of
     
    18101817    \endlist
    18111818
    1812 
    1813     \section2 The Direct Approach
    1814 
    1815     To demonstrate how to use user interface (UI) files straight from
    1816     \QD, we create a simple Calculator Form application. This is based on the
     1819    To demonstrate, we create a simple Calculator Form application. It is based on the
    18171820    original \l{Calculator Form Example}{Calculator Form} example.
    18181821
     
    18321835    \c qmake which files to process with \c uic. In this case, the
    18331836    \c calculatorform.ui file is used to create a \c ui_calculatorform.h file
    1834     that can be used by any file listed in the \c SOURCES declaration. To
    1835     ensure that \c qmake generates the \c ui_calculatorform.h file, we need to
    1836     include it in a file listed in \c SOURCES. Since we only have \c main.cpp,
    1837     we include it there:
     1837    that can be used by any file listed in the \c SOURCES declaration.
     1838
     1839    \note You can use Qt Creator to create the Calculator Form project. It
     1840    automatically generates the main.cpp, UI, and .pro files, which you can
     1841    then modify.
     1842
     1843    \section2 The Direct Approach
     1844
     1845    To use the direct approach, we include the \c ui_calculatorform.h file
     1846    directly in \c main.cpp:
    18381847
    18391848    \snippet doc/src/snippets/uitools/calculatorform/main.cpp 0
    1840 
    1841     This include is an additional check to ensure that we do not generate code
    1842     for UI files that are not used.
    18431849
    18441850    The \c main function creates the calculator widget by constructing a
     
    18521858    and the connections between its signals and slots.
    18531859
    1854     This approach provides a quick and easy way to use simple, self-contained
    1855     components in your applications, but many componens created with \QD will
     1860    The direct approach provides a quick and easy way to use simple, self-contained
     1861    components in your applications. However, componens created with \QD often
    18561862    require close integration with the rest of the application code. For
    18571863    instance, the \c CalculatorForm code provided above will compile and run,
    18581864    but the QSpinBox objects will not interact with the QLabel as we need a
    18591865    custom slot to carry out the add operation and display the result in the
    1860     QLabel. To achieve this, we need to subclass a standard Qt widget (known as
    1861     the single inheritance approach).
    1862 
     1866    QLabel. To achieve this, we need to use the single inheritance approach.
    18631867
    18641868    \section2 The Single Inheritance Approach
     1869
     1870    To use the single inheritance approach, we subclass a standard Qt widget and
     1871    include a private instance of the form's user interface object. This can take
     1872    the form of:
     1873
     1874    \list
     1875        \o A member variable
     1876        \o A pointer member variable
     1877    \endlist
     1878
     1879    \section3 Using a Member Variable
    18651880
    18661881    In this approach, we subclass a Qt widget and set up the user interface
     
    18691884    standard system for making signal and slot connections between the user
    18701885    interface and other objects in your application.
     1886    The generated \c{Ui::CalculatorForm} structure is a member of the class.
    18711887
    18721888    This approach is used in the \l{Calculator Form Example}{Calculator Form}
     
    19081924    forms, for example.
    19091925
     1926    \section3 Using a Pointer Member Variable
     1927
     1928    Alternatively, the \c{Ui::CalculatorForm} structure can be made a pointer
     1929    member of the class. The header then looks as follows:
     1930
     1931    \code
     1932
     1933    namespace Ui {
     1934        class CalculatorForm;
     1935    }
     1936
     1937    class CalculatorForm : public QWidget
     1938    ...
     1939    virtual ~CalculatorForm();
     1940    ...
     1941    private:
     1942        Ui::CalculatorForm *ui;
     1943    ...
     1944
     1945    \endcode
     1946
     1947    The corresponding source file looks as follows:
     1948
     1949    \code
     1950    #include "ui_calculatorform.h"
     1951
     1952    CalculatorForm::CalculatorForm(QWidget *parent) :
     1953        QWidget(parent), ui(new Ui::CalculatorForm)
     1954    {
     1955        ui->setupUi(this);
     1956    }
     1957
     1958    CalculatorForm::~CalculatorForm()
     1959    {
     1960        delete ui;
     1961    }
     1962    \endcode
     1963
     1964    The advantage of this approach is that the user interface object can be
     1965    forward-declared, which means that we do not have to include the generated
     1966    \c ui_calculatorform.h file in the header. The form can then be changed without
     1967    recompiling the dependent source files. This is particularly important if the
     1968    class is subject to binary compatibility restrictions.
     1969
     1970    We generally recommend this approach for libraries and large applications.
     1971    For more information, see \l{Creating Shared Libraries}.
    19101972
    19111973    \section2 The Multiple Inheritance Approach
     
    19211983
    19221984    We need to include the header file that \c uic generates from the
    1923     \c calculatorform.ui file:
     1985    \c calculatorform.ui file, as follows:
    19241986
    19251987    \snippet examples/uitools/multipleinheritance/calculatorform.h 0
     
    19271989    The class is defined in a similar way to the one used in the
    19281990    \l{The Single Inheritance Approach}{single inheritance approach}, except that
    1929     this time we inherit from \e{both} QWidget and \c{Ui::CalculatorForm}:
     1991    this time we inherit from \e{both} QWidget and \c{Ui::CalculatorForm},
     1992    as follows:
    19301993
    19311994    \snippet examples/uitools/multipleinheritance/calculatorform.h 1
     
    19462009    \c{ui} prefix to access them.
    19472010
    1948     Subclassing using multiple inheritance gives us more direct access to the
    1949     contents of the form, is slightly cleaner than the single inheritance
    1950     approach, but does not conveniently support composition of multiple user
    1951     interfaces.
    1952 
     2011    \section2 Reacting to Language Changes
     2012
     2013    Qt notifies applications if the user interface language changes by sending an
     2014    event of the type QEvent::LanguageChange. To call the member function
     2015    \c retranslateUi() of the user interface object, we reimplement
     2016    \c QWidget::changeEvent() in the form class, as follows:
     2017
     2018    \code
     2019    void CalculatorForm::changeEvent(QEvent *e)
     2020    {
     2021        QWidget::changeEvent(e);
     2022        switch (e->type()) {
     2023        case QEvent::LanguageChange:
     2024            ui->retranslateUi(this);
     2025            break;
     2026        default:
     2027            break;
     2028       }
     2029    }
     2030    \endcode
    19532031
    19542032    \section1 Run Time Form Processing
     
    27772855
    27782856    \legalese
    2779     Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). \BR
     2857    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). \BR
    27802858    Copyright (C) 2005 Bjoern Bergstroem
    27812859
Note: See TracChangeset for help on using the changeset viewer.