Changeset 846 for trunk/doc/src/development/designer-manual.qdoc
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/doc/src/development/designer-manual.qdoc
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the documentation of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE: LGPL$9 ** $QT_BEGIN_LICENSE:FDL$ 10 10 ** Commercial Usage 11 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** awritten agreement between you and Nokia.13 ** Software or, alternatively, in accordance with the terms contained in a 14 ** written agreement between you and Nokia. 15 15 ** 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. 35 21 ** 36 22 ** If you have questions regarding the use of this file, please contact … … 1784 1770 \title Using a Designer UI File in Your Application 1785 1771 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 1793 1782 1794 1783 \tableofcontents 1795 1784 \section1 Compile Time Form Processing 1796 1785 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 1797 1804 A compile time processed form can be used in your application with one of 1798 1805 the following approaches: 1799 1806 1800 1807 \list 1801 \o The Direct Approach: you construct a widget to use as a placeholder1808 \o \l{The Direct Approach}: you construct a widget to use as a placeholder 1802 1809 for the component, and set up the user interface inside it. 1803 \o The Single Inheritance Approach: you subclass the form's base class1810 \o \l{The Single Inheritance Approach}: you subclass the form's base class 1804 1811 (QWidget or QDialog, for example), and include a private instance 1805 1812 of the form's user interface object. 1806 \o The MultipleInheritance Approach: you subclass both the form's base1813 \o \l{The Multiple Inheritance Approach}: you subclass both the form's base 1807 1814 class and the form's user interface object. This allows the widgets 1808 1815 defined in the form to be used directly from within the scope of … … 1810 1817 \endlist 1811 1818 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 1817 1820 original \l{Calculator Form Example}{Calculator Form} example. 1818 1821 … … 1832 1835 \c qmake which files to process with \c uic. In this case, the 1833 1836 \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: 1838 1847 1839 1848 \snippet doc/src/snippets/uitools/calculatorform/main.cpp 0 1840 1841 This include is an additional check to ensure that we do not generate code1842 for UI files that are not used.1843 1849 1844 1850 The \c main function creates the calculator widget by constructing a … … 1852 1858 and the connections between its signals and slots. 1853 1859 1854 Th isapproach provides a quick and easy way to use simple, self-contained1855 components in your applications , but many componens created with \QD will1860 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 1856 1862 require close integration with the rest of the application code. For 1857 1863 instance, the \c CalculatorForm code provided above will compile and run, 1858 1864 but the QSpinBox objects will not interact with the QLabel as we need a 1859 1865 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. 1863 1867 1864 1868 \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 1865 1880 1866 1881 In this approach, we subclass a Qt widget and set up the user interface … … 1869 1884 standard system for making signal and slot connections between the user 1870 1885 interface and other objects in your application. 1886 The generated \c{Ui::CalculatorForm} structure is a member of the class. 1871 1887 1872 1888 This approach is used in the \l{Calculator Form Example}{Calculator Form} … … 1908 1924 forms, for example. 1909 1925 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}. 1910 1972 1911 1973 \section2 The Multiple Inheritance Approach … … 1921 1983 1922 1984 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: 1924 1986 1925 1987 \snippet examples/uitools/multipleinheritance/calculatorform.h 0 … … 1927 1989 The class is defined in a similar way to the one used in the 1928 1990 \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: 1930 1993 1931 1994 \snippet examples/uitools/multipleinheritance/calculatorform.h 1 … … 1946 2009 \c{ui} prefix to access them. 1947 2010 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 1953 2031 1954 2032 \section1 Run Time Form Processing … … 2777 2855 2778 2856 \legalese 2779 Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies). \BR2857 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). \BR 2780 2858 Copyright (C) 2005 Bjoern Bergstroem 2781 2859
Note:
See TracChangeset
for help on using the changeset viewer.