Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit d0dadf7

Browse files
author
mttwc
committed
Demonstrates form layout
1 parent ec8157a commit d0dadf7

File tree

6 files changed

+38
-55
lines changed

6 files changed

+38
-55
lines changed

HelloQt.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
QT += widgets
77

88
SOURCES = src/main.cpp \
9-
src/nesting_demonstration.cpp \
9+
src/form_demonstration.cpp \
1010

11-
HEADERS = src/nesting_demonstration.h
11+
HEADERS = src/form_demonstration.h
1212

1313
CONFIG -= app_bundle
1414

src/form_demonstration.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <QFormLayout>
2+
#include <QLabel>
3+
#include <QLineEdit>
4+
#include "form_demonstration.h"
5+
6+
FormDemonstration::FormDemonstration(QWidget *parent)
7+
: QWidget(parent)
8+
{
9+
QLineEdit *nameEdit = new QLineEdit(this);
10+
QLineEdit *addrEdit = new QLineEdit(this);
11+
QLineEdit *occpEdit = new QLineEdit(this);
12+
13+
QFormLayout *formLayout = new QFormLayout;
14+
// Horizontally, align right. Vertically, align center.
15+
formLayout->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
16+
formLayout->addRow("Name:", nameEdit);
17+
formLayout->addRow("Email:", addrEdit);
18+
formLayout->addRow("Occupation:", occpEdit);
19+
20+
setLayout(formLayout);
21+
}

src/form_demonstration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef FORM_DEMONSTRATION_H
2+
#define FORM_DEMONSTRATION_H
3+
4+
#include <QWidget>
5+
6+
class FormDemonstration : public QWidget
7+
{
8+
public:
9+
FormDemonstration(QWidget *parent = 0);
10+
};
11+
12+
#endif

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <QApplication>
22
#include <QWidget>
3-
#include "nesting_demonstration.h"
3+
#include "form_demonstration.h"
44

55
int main(int argc, char *argv[])
66
{
77
QApplication app(argc, argv);
88

9-
NestingDemonstration window;
9+
FormDemonstration window;
1010

11-
window.setWindowTitle("Nesting Layout Demonstration");
11+
window.setWindowTitle("Form Layout Demonstration");
1212
window.show();
1313

1414
return app.exec();

src/nesting_demonstration.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/nesting_demonstration.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)