0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the documentation of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
/*!
|
|
43 |
\example dialogs/tabdialog
|
|
44 |
\title Tab Dialog Example
|
|
45 |
|
|
46 |
The Tab Dialog example shows how to construct a tab dialog using the
|
|
47 |
QTabWidget class.
|
|
48 |
|
|
49 |
Dialogs provide an efficient way for the application to communicate
|
|
50 |
with the user, but complex dialogs suffer from the problem that they
|
|
51 |
often take up too much screen area. By using a number of tabs in a
|
|
52 |
dialog, information can be split into different categories, while
|
|
53 |
remaining accessible.
|
|
54 |
|
|
55 |
\image tabdialog-example.png
|
|
56 |
|
|
57 |
The Tab Dialog example consists of a single \c TabDialog class that
|
|
58 |
provides three tabs, each containing information about a particular
|
|
59 |
file, and two standard push buttons that are used to accept or reject
|
|
60 |
the contents of the dialog.
|
|
61 |
|
|
62 |
\section1 TabDialog Class Definition
|
|
63 |
|
|
64 |
The \c TabDialog class is a subclass of QDialog that displays a
|
|
65 |
QTabWidget and two standard dialog buttons. The class definition
|
|
66 |
only contain the class constructor and a private data member for
|
|
67 |
the QTabWidget:
|
|
68 |
|
|
69 |
\snippet examples/dialogs/tabdialog/tabdialog.h 3
|
|
70 |
|
|
71 |
In the example, the widget will be used as a top-level window, but
|
|
72 |
we define the constructor so that it can take a parent widget. This
|
|
73 |
allows the dialog to be centered on top of an application's main
|
|
74 |
window.
|
|
75 |
|
|
76 |
\section1 TabDialog Class Implementation
|
|
77 |
|
|
78 |
The constructor calls the QDialog constructor and creates a QFileInfo
|
|
79 |
object for the specified filename.
|
|
80 |
|
|
81 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 0
|
|
82 |
|
|
83 |
The tab widget is populated with three custom widgets that each
|
|
84 |
contain information about the file. We construct each of these
|
|
85 |
without a parent widget because the tab widget will reparent
|
|
86 |
them as they are added to it.
|
|
87 |
|
|
88 |
We create two standard push buttons, and connect each of them to
|
|
89 |
the appropriate slots in the dialog:
|
|
90 |
|
|
91 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 1
|
|
92 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 3
|
|
93 |
|
|
94 |
We arrange the tab widget above the buttons in the dialog:
|
|
95 |
|
|
96 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 4
|
|
97 |
|
|
98 |
Finally, we set the dialog's title:
|
|
99 |
|
|
100 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 5
|
|
101 |
|
|
102 |
Each of the tabs are subclassed from QWidget, and only provide
|
|
103 |
constructors.
|
|
104 |
|
|
105 |
\section1 GeneralTab Class Definition
|
|
106 |
|
|
107 |
The GeneralTab widget definition is simple because we are only interested
|
|
108 |
in displaying the contents of a widget within a tab:
|
|
109 |
|
|
110 |
\snippet examples/dialogs/tabdialog/tabdialog.h 0
|
|
111 |
|
|
112 |
\section1 GeneralTab Class Implementation
|
|
113 |
|
|
114 |
The GeneralTab widget simply displays some information about the file
|
|
115 |
passed by the TabDialog. Various widgets for this purpose, and these
|
|
116 |
are arranged within a vertical layout:
|
|
117 |
|
|
118 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 6
|
|
119 |
|
|
120 |
\section1 PermissionsTab Class Definition
|
|
121 |
|
|
122 |
Like the GeneralTab, the PermissionsTab is just used as a placeholder
|
|
123 |
widget for its children:
|
|
124 |
|
|
125 |
\snippet examples/dialogs/tabdialog/tabdialog.h 1
|
|
126 |
|
|
127 |
\section1 PermissionsTab Class Implementation
|
|
128 |
|
|
129 |
The PermissionsTab shows information about the file's access information,
|
|
130 |
displaying details of the file permissions and owner in widgets that are
|
|
131 |
arranged in nested layouts:
|
|
132 |
|
|
133 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 7
|
|
134 |
|
|
135 |
\section1 ApplicationsTab Class Definition
|
|
136 |
|
|
137 |
The ApplicationsTab is another placeholder widget that is mostly
|
|
138 |
cosmetic:
|
|
139 |
|
|
140 |
\snippet examples/dialogs/tabdialog/tabdialog.h 2
|
|
141 |
|
|
142 |
\section1 ApplicationsTab Class Implementation
|
|
143 |
|
|
144 |
The ApplicationsTab does not show any useful information, but could be
|
|
145 |
used as a template for a more complicated example:
|
|
146 |
|
|
147 |
\snippet examples/dialogs/tabdialog/tabdialog.cpp 8
|
|
148 |
*/
|