From f0868f7fc3dacfa6b5b4bcee90b9b0a79d2ccd2a Mon Sep 17 00:00:00 2001 From: Jerome Pasion Date: Mon, 13 Sep 2010 15:08:00 +0200 Subject: Added a QFormLayout snippet to the layout.qdoc and layouts.cpp Reviewed-by: David Boddie Tasks: QTBUG-10077 --- doc/src/snippets/layouts/layouts.cpp | 42 ++++++++++++++++++++++++++++++--- doc/src/widgets-and-layouts/layout.qdoc | 16 +++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/doc/src/snippets/layouts/layouts.cpp b/doc/src/snippets/layouts/layouts.cpp index 66c9b9d..58440f5 100644 --- a/doc/src/snippets/layouts/layouts.cpp +++ b/doc/src/snippets/layouts/layouts.cpp @@ -66,7 +66,9 @@ int main(int argc, char *argv[]) layout->addWidget(button5); window->setLayout(layout); -//! [4] //! [5] +//! [4] + window->setWindowTitle("QHBoxLayout"); +//! [5] window->show(); //! [5] } @@ -93,7 +95,9 @@ int main(int argc, char *argv[]) layout->addWidget(button5); window->setLayout(layout); -//! [10] //! [11] +//! [10] + window->setWindowTitle("QVBoxLayout"); +//! [11] window->show(); //! [11] } @@ -120,10 +124,42 @@ int main(int argc, char *argv[]) layout->addWidget(button5, 2, 1); window->setLayout(layout); -//! [16] //! [17] +//! [16] + window->setWindowTitle("QGridLayout"); +//! [17] window->show(); //! [17] } + { +//! [18] + QWidget *window = new QWidget; +//! [18] +//! [19] + QPushButton *button1 = new QPushButton("One"); + QLineEdit *lineEdit1 = new QLineEdit(); +//! [19] +//! [20] + QPushButton *button2 = new QPushButton("Two"); + QLineEdit *lineEdit2 = new QLineEdit(); + QPushButton *button3 = new QPushButton("Three"); + QLineEdit *lineEdit3 = new QLineEdit(); +//! [20] +//! [21] + QFormLayout *layout = new QFormLayout; +//! [21] +//! [22] + layout->addRow(button1, lineEdit1); + layout->addRow(button2, lineEdit2); + layout->addRow(button3, lineEdit3); + + window->setLayout(layout); +//! [22] + window->setWindowTitle("QFormLayout"); +//! [23] + window->show(); +//! [23] + } + return app.exec(); } diff --git a/doc/src/widgets-and-layouts/layout.qdoc b/doc/src/widgets-and-layouts/layout.qdoc index 32dddd7..4db991a 100644 --- a/doc/src/widgets-and-layouts/layout.qdoc +++ b/doc/src/widgets-and-layouts/layout.qdoc @@ -116,7 +116,7 @@ \section2 Laying Out Widgets in Code The following code creates a QHBoxLayout that manages the geometry of five - \l{QPushButton}s, as shown on the first screenshot above: + \l{QPushButton}{QPushButtons}, as shown on the first screenshot above: \snippet doc/src/snippets/layouts/layouts.cpp 0 \snippet doc/src/snippets/layouts/layouts.cpp 1 @@ -141,7 +141,19 @@ The third QPushButton spans 2 columns. This is possible by specifying 2 as the fifth argument to QGridLayout::addWidget(). - Finally, the code for QFormLayout is .. + QFormLayout will add two widgets on a row, commonly a QLabel and a QLineEdit + to create forms. Adding a QLabel and a QLineEdit on the same row will set + the QLineEdit as the QLabel's buddy. The following code will use the + QFormLayout to place three \l{QPushButton}{QPushButtons} and a corresponding + QLineEdit on a row. + + \snippet doc/src/snippets/layouts/layouts.cpp 18 + \snippet doc/src/snippets/layouts/layouts.cpp 19 + \snippet doc/src/snippets/layouts/layouts.cpp 20 + \codeline + \snippet doc/src/snippets/layouts/layouts.cpp 21 + \snippet doc/src/snippets/layouts/layouts.cpp 22 + \snippet doc/src/snippets/layouts/layouts.cpp 23 \section2 Tips for Using Layouts -- cgit v0.12