Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qformlayout.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFORMLAYOUT_H
5#define QFORMLAYOUT_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/QLayout>
9
11
13
14
16
17class Q_WIDGETS_EXPORT QFormLayout : public QLayout
18{
20 Q_DECLARE_PRIVATE(QFormLayout)
21 Q_PROPERTY(FieldGrowthPolicy fieldGrowthPolicy READ fieldGrowthPolicy WRITE setFieldGrowthPolicy
22 RESET resetFieldGrowthPolicy)
23 Q_PROPERTY(RowWrapPolicy rowWrapPolicy READ rowWrapPolicy WRITE setRowWrapPolicy
24 RESET resetRowWrapPolicy)
25 Q_PROPERTY(Qt::Alignment labelAlignment READ labelAlignment WRITE setLabelAlignment
26 RESET resetLabelAlignment)
27 Q_PROPERTY(Qt::Alignment formAlignment READ formAlignment WRITE setFormAlignment
28 RESET resetFormAlignment)
29 Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
30 Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
31
32public:
36 AllNonFixedFieldsGrow
37 };
38 Q_ENUM(FieldGrowthPolicy)
39
43 WrapAllRows
44 };
45 Q_ENUM(RowWrapPolicy)
46
47 enum ItemRole {
48 LabelRole = 0,
49 FieldRole = 1,
50 SpanningRole = 2
51 };
52 Q_ENUM(ItemRole)
53
57 };
58
59 explicit QFormLayout(QWidget *parent = nullptr);
61
63 FieldGrowthPolicy fieldGrowthPolicy() const;
65 RowWrapPolicy rowWrapPolicy() const;
66 void setLabelAlignment(Qt::Alignment alignment);
67 Qt::Alignment labelAlignment() const;
68 void setFormAlignment(Qt::Alignment alignment);
69 Qt::Alignment formAlignment() const;
70
71 void setHorizontalSpacing(int spacing);
72 int horizontalSpacing() const;
73 void setVerticalSpacing(int spacing);
74 int verticalSpacing() const;
75
76 int spacing() const override;
77 void setSpacing(int) override;
78
79 void addRow(QWidget *label, QWidget *field);
80 void addRow(QWidget *label, QLayout *field);
81 void addRow(const QString &labelText, QWidget *field);
82 void addRow(const QString &labelText, QLayout *field);
83 void addRow(QWidget *widget);
84 void addRow(QLayout *layout);
85
86 void insertRow(int row, QWidget *label, QWidget *field);
87 void insertRow(int row, QWidget *label, QLayout *field);
88 void insertRow(int row, const QString &labelText, QWidget *field);
89 void insertRow(int row, const QString &labelText, QLayout *field);
90 void insertRow(int row, QWidget *widget);
91 void insertRow(int row, QLayout *layout);
92
93 void removeRow(int row);
96
97 TakeRowResult takeRow(int row);
100
101 void setItem(int row, ItemRole role, QLayoutItem *item);
102 void setWidget(int row, ItemRole role, QWidget *widget);
103 void setLayout(int row, ItemRole role, QLayout *layout);
104
105 void setRowVisible(int row, bool on);
106 void setRowVisible(QWidget *widget, bool on);
107 void setRowVisible(QLayout *layout, bool on);
108
109 bool isRowVisible(int row) const;
110 bool isRowVisible(QWidget *widget) const;
111 bool isRowVisible(QLayout *layout) const;
112
113 QLayoutItem *itemAt(int row, ItemRole role) const;
114 void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
115 void getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
116 void getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const;
117 QWidget *labelForField(QWidget *field) const;
118 QWidget *labelForField(QLayout *field) const;
119
120 // reimplemented from QLayout
121 void addItem(QLayoutItem *item) override;
122 QLayoutItem *itemAt(int index) const override;
123 QLayoutItem *takeAt(int index) override;
124
125 void setGeometry(const QRect &rect) override;
126 QSize minimumSize() const override;
127 QSize sizeHint() const override;
128 void invalidate() override;
129
130 bool hasHeightForWidth() const override;
131 int heightForWidth(int width) const override;
132 Qt::Orientations expandingDirections() const override;
133 int count() const override;
134
135 int rowCount() const;
136
137#if 0
138 void dump() const;
139#endif
140
141private:
142 void resetFieldGrowthPolicy();
143 void resetRowWrapPolicy();
144 void resetLabelAlignment();
145 void resetFormAlignment();
146};
147
149
151
152#endif
The QFormLayout class manages forms of input widgets and their associated labels.
Definition qformlayout.h:18
RowWrapPolicy
This enum specifies the different policies that can be used to control the way in which the form's ro...
Definition qformlayout.h:40
ItemRole
This enum specifies the types of widgets (or other layout items) that may appear in a row.
Definition qformlayout.h:47
FieldGrowthPolicy
This enum specifies the different policies that can be used to control the way in which the form's fi...
Definition qformlayout.h:33
@ FieldsStayAtSizeHint
Definition qformlayout.h:34
@ ExpandingFieldsGrow
Definition qformlayout.h:35
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition qlayoutitem.h:25
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width, which is not used in this default...
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
int spacing
the spacing between widgets inside the layout
Definition qlayout.h:30
virtual void setSpacing(int)
Definition qlayout.cpp:266
virtual void addItem(QLayoutItem *)=0
Implemented in subclasses to add an item.
virtual QLayoutItem * itemAt(int index) const =0
Must be implemented in subclasses to return the layout item at index.
virtual QLayoutItem * takeAt(int index)=0
Must be implemented in subclasses to remove the layout item at index from the layout,...
Qt::Orientations expandingDirections() const override
Returns whether this layout can make use of more space than sizeHint().
Definition qlayout.cpp:943
QSize minimumSize() const override
Returns the minimum size of this layout.
Definition qlayout.cpp:911
void invalidate() override
\reimp
Definition qlayout.cpp:469
virtual int count() const =0
Must be implemented in subclasses to return the number of items in the layout.
virtual void setGeometry(const QRect &) override
\reimp
Definition qlayout.cpp:451
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
qreal spacing
rect
[4]
uint alignment
Combined button and popup list for selecting options.
GLuint index
[2]
GLint GLsizei width
GLuint GLsizei const GLchar * label
[43]
GLenum GLenum GLsizei void * row
static QString dump(const QByteArray &)
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:144
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
QVBoxLayout * layout
QGraphicsItem * item
layout addRow(numberLabel, numberEdit)
formLayout setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint)
formLayout setLabelAlignment(Qt::AlignLeft)
flay removeRow(2)
formLayout setFormAlignment(Qt::AlignHCenter|Qt::AlignTop)
flay insertRow(2, "User:", le)
formLayout setRowWrapPolicy(QFormLayout::DontWrapRows)
[1]
scrollArea setWidget(imageLabel)
QSizePolicy policy
Contains the result of a QFormLayout::takeRow() call.
Definition qformlayout.h:54
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent