Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
b675fe20
Commit
b675fe20
authored
Jun 03, 2009
by
Kavindra Devi Palaraja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes: Doc - more of Part2, hoping to finish it today
RevBy: TrustMe
parent
330b6e27
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
13 deletions
+69
-13
doc/addressbook-sdk.qdoc
doc/addressbook-sdk.qdoc
+39
-6
doc/examples/addressbook-sdk/part2/addressbook.cpp
doc/examples/addressbook-sdk/part2/addressbook.cpp
+26
-3
doc/examples/addressbook-sdk/part2/addressbook.ui
doc/examples/addressbook-sdk/part2/addressbook.ui
+4
-4
No files found.
doc/addressbook-sdk.qdoc
View file @
b675fe20
...
...
@@ -269,12 +269,13 @@
\section1 Placing Widgets on the Form
Now that we have the labels and input fields set up, we add push buttons to
complete the process of adding a contact. So, we begin by breaking the
existing layouts. Then, we add three push buttons. Double-click on each of
them to set their text to "Add", "Submit", and "Cancel". We now require a
vertical spacer to ensure that the push buttons will be laid out neatly;
drag one from the \gui{Widget Box}.
We shall continue with the form we had from the last chapter; we have the
labels and input fields set up, but we need to add push buttons to complete
the process of adding a contact. So, we begin by breaking the existing
layouts. Then, we add three push buttons. Double-click on each of them to
set their text to "Add", "Submit", and "Cancel". We now require a vertical
spacer to ensure that the push buttons will be laid out neatly; drag one
from the \gui{Widget Box}.
Next, lay out these three push buttons and the spacer vertically, by
selecting all three of them (using the \key{Ctrl + click}) and choosing
...
...
@@ -312,6 +313,8 @@
Next, we have to provide private members for the \c AddressBook class so
that we can access these members freely throughout the application.
\snippet examples/addressbook-sdk/part2/addressbook.h members1
\note The names, e.g., \c addButton etc., correspond to the name of the
actual object. You can modify them by double-clicking on their names within
\QD's \gui{Object Inspector}.
...
...
@@ -321,4 +324,34 @@
purpose as it holds a key-value pair: the contact's name as the \e key, and
the contact's address as the \e value.
\snippet examples/addressbook-sdk/part2/addressbook.h members2
We also declare two private QString objects, \c oldName and \c oldAddress.
These objects are needed to hold the name and address of hte contact that
was last displayed, before the user clicked \gui Add. So, when the user
clicks \gui Cancel, we can revert to displaying the details of the last
contact.
Let's move on to implementing the slots we defined earlier. Within the
constructor of \c AddressBook, we extract the widgets from the form using
the \c ui object by pointing our private members to them.
\snippet examples/addressbook-sdk/part2/addressbook.cpp extract objects
Then we set \c nameLine and \c addressText to read-only, so that we can
only display but not edit existing contact details. We also hide
\c submitButton and \c cancelButton as they will only be be displayed
when the user clicks \gui Add, and this is handled by the \c addContact()
function discussed below.
\snippet examples/addressbook-sdk/part2/addressbook.cpp signal slot
We connect the push buttons' \l{QAbstractButton::clicked()}{clicked()}
signal to their respective slots. The figure below illustrates this.
#image
\section2 The \c{addContact()} Function
*/
doc/examples/addressbook-sdk/part2/addressbook.cpp
View file @
b675fe20
...
...
@@ -6,14 +6,37 @@ AddressBook::AddressBook(QWidget *parent)
{
ui
->
setupUi
(
this
);
addButton
=
new
QPushButton
();
//! [extract objects]
nameLine
=
new
QLineEdit
;
nameLine
=
ui
->
nameLine
;
nameLine
->
setReadOnly
(
true
);
addressText
=
new
QTextEdit
;
addressText
=
ui
->
addressText
;
addressText
->
setReadOnly
(
true
);
addButton
=
new
QPushButton
;
addButton
=
ui
->
addButton
;
submitButton
=
new
QPushButton
()
;
submitButton
=
new
QPushButton
;
submitButton
=
ui
->
submitButton
;
submitButton
->
hide
();
cancelButton
=
new
QPushButton
()
;
cancelButton
=
new
QPushButton
;
cancelButton
=
ui
->
cancelButton
;
cancelButton
->
hide
();
//! [extract objects]
//! [signal slot]
connect
(
addButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
addContact
()));
connect
(
submitButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
submitContact
()));
connect
(
cancelButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
cancel
()));
//! [signal slot]
setWindowTitle
(
tr
(
"Simple Address Book"
));
}
AddressBook
::~
AddressBook
()
...
...
doc/examples/addressbook-sdk/part2/addressbook.ui
View file @
b675fe20
...
...
@@ -17,17 +17,17 @@
<item>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<item
row=
"0"
column=
"0"
>
<widget
class=
"QLabel"
name=
"name
Edit
"
>
<widget
class=
"QLabel"
name=
"name
Label
"
>
<property
name=
"text"
>
<string>
Name:
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
>
<widget
class=
"QLineEdit"
name=
"
lineEdit
"
/>
<widget
class=
"QLineEdit"
name=
"
nameLine
"
/>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QLabel"
name=
"address
Edit
"
>
<widget
class=
"QLabel"
name=
"address
Label
"
>
<property
name=
"text"
>
<string>
Address:
</string>
</property>
...
...
@@ -37,7 +37,7 @@
</widget>
</item>
<item
row=
"1"
column=
"1"
>
<widget
class=
"QTextEdit"
name=
"
textEdi
t"
/>
<widget
class=
"QTextEdit"
name=
"
addressTex
t"
/>
</item>
<item
row=
"1"
column=
"2"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment