source: trunk/doc/src/examples/extension.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

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

File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
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.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at qt-info@nokia.com.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \example dialogs/extension
30 \title Extension Example
31
32 The Extension example shows how to add an extension to a QDialog
33 using the QAbstractButton::toggled() signal and the
34 QWidget::setVisible() slot.
35
36 \image extension-example.png Screenshot of the Extension example
37
38 The Extension application is a dialog that allows the user to
39 perform a simple search as well as a more advanced search.
40
41 The simple search has two options: \gui {Match case} and \gui
42 {Search from start}. The advanced search options include the
43 possibilities to search for \gui {Whole words}, \gui {Search
44 backward} and \gui {Search selection}. Only the simple search is
45 visible when the application starts. The advanced search options
46 are located in the application's extension part, and can be made
47 visible by pressing the \gui More button:
48
49 \image extension_more.png Screenshot of the Extension example
50
51 \section1 FindDialog Class Definition
52
53 The \c FindDialog class inherits QDialog. The QDialog class is the
54 base class of dialog windows. A dialog window is a top-level
55 window mostly used for short-term tasks and brief communications
56 with the user.
57
58 \snippet examples/dialogs/extension/finddialog.h 0
59
60 The \c FindDialog widget is the main application widget, and
61 displays the application's search options and controlling
62 buttons.
63
64 In addition to a constructor, we declare the several child
65 widgets: We need a QLineEdit with an associated QLabel to let the
66 user type a word to search for, we need several \l
67 {QCheckBox}{QCheckBox}es to facilitate the search options, and we
68 need three \l {QPushButton}{QPushButton}s: the \gui Find button to
69 start a search and the \gui More button to enable an advanced search.
70 Finally, we need a QWidget representing the application's extension
71 part.
72
73 \section1 FindDialog Class Implementation
74
75 In the constructor we first create the standard child widgets for
76 the simple search: the QLineEdit with the associated QLabel, two
77 of the \l {QCheckBox}{QCheckBox}es and all the \l
78 {QPushButton}{QPushButton}s.
79
80 \snippet examples/dialogs/extension/finddialog.cpp 0
81
82 We give the options and buttons a shortcut key using the &
83 character. In the \gui {Find what} option's case, we also need to
84 use the QLabel::setBuddy() function to make the shortcut key work
85 as expected; then, when the user presses the shortcut key
86 indicated by the label, the keyboard focus is transferred to the
87 label's buddy widget, the QLineEdit.
88
89 We set the \gui Find button's default property to true, using the
90 QPushButton::setDefault() function. Then the push button will be
91 pressed if the user presses the Enter (or Return) key. Note that a
92 QDialog can only have one default button.
93
94 \snippet examples/dialogs/extension/finddialog.cpp 2
95
96 Then we create the extension widget, and the \l
97 {QCheckBox}{QCheckBox}es associated with the advanced search
98 options.
99
100 \snippet examples/dialogs/extension/finddialog.cpp 3
101
102 Now that the extension widget is created, we can connect the \gui
103 More button's \l{QAbstractButton::toggled()}{toggled()} signal to
104 the extension widget's \l{QWidget::setVisible()}{setVisible()} slot.
105
106 The QAbstractButton::toggled() signal is emitted whenever a
107 checkable button changes its state. The signal's argument is true
108 if the button is checked, or false if the button is unchecked. The
109 QWidget::setVisible() slot sets the widget's visible status. If
110 the status is true the widget is shown, otherwise the widget is
111 hidden.
112
113 Since we made the \gui More button checkable when we created it,
114 the connection makes sure that the extension widget is shown
115 depending on the state of \gui More button.
116
117 We also put the check boxes associated with the advanced
118 search options into a layout we install on the extension widget.
119
120 \snippet examples/dialogs/extension/finddialog.cpp 4
121
122 Before we create the main layout, we create several child layouts
123 for the widgets: First we allign the QLabel ans its buddy, the
124 QLineEdit, using a QHBoxLayout. Then we vertically allign the
125 QLabel and QLineEdit with the check boxes associated with the
126 simple search, using a QVBoxLayout. We also create a QVBoxLayout
127 for the buttons. In the end we lay out the two latter layouts and
128 the extension widget using a QGridLayout.
129
130 \snippet examples/dialogs/extension/finddialog.cpp 5
131
132 Finally, we hide the extension widget using the QWidget::hide()
133 function, making the application only show the simple search
134 options when it starts. When the user wants to access the advanced
135 search options, the dialog only needs to change the visibility of
136 the extension widget. Qt's layout management takes care of the
137 dialog's appearance.
138*/
Note: See TracBrowser for help on using the repository browser.