Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QFORMLAYOUT_H
6#define QFORMLAYOUT_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtWidgets/QLayout>
10
12
13QT_BEGIN_NAMESPACE
14
15
16class QFormLayoutPrivate;
17
18class Q_WIDGETS_EXPORT QFormLayout : public QLayout
19{
20 Q_OBJECT
21 Q_DECLARE_PRIVATE(QFormLayout)
22 Q_PROPERTY(FieldGrowthPolicy fieldGrowthPolicy READ fieldGrowthPolicy WRITE setFieldGrowthPolicy
23 RESET resetFieldGrowthPolicy)
24 Q_PROPERTY(RowWrapPolicy rowWrapPolicy READ rowWrapPolicy WRITE setRowWrapPolicy
25 RESET resetRowWrapPolicy)
26 Q_PROPERTY(Qt::Alignment labelAlignment READ labelAlignment WRITE setLabelAlignment
27 RESET resetLabelAlignment)
28 Q_PROPERTY(Qt::Alignment formAlignment READ formAlignment WRITE setFormAlignment
29 RESET resetFormAlignment)
30 Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
31 Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
32
33public:
34 enum FieldGrowthPolicy {
35 FieldsStayAtSizeHint,
36 ExpandingFieldsGrow,
37 AllNonFixedFieldsGrow
38 };
39 Q_ENUM(FieldGrowthPolicy)
40
41 enum RowWrapPolicy {
42 DontWrapRows,
43 WrapLongRows,
44 WrapAllRows
45 };
46 Q_ENUM(RowWrapPolicy)
47
48 enum ItemRole {
49 LabelRole = 0,
50 FieldRole = 1,
51 SpanningRole = 2
52 };
53 Q_ENUM(ItemRole)
54
55 struct TakeRowResult {
56 QLayoutItem *labelItem;
57 QLayoutItem *fieldItem;
58 };
59
60 explicit QFormLayout(QWidget *parent = nullptr);
61 ~QFormLayout();
62
63 void setFieldGrowthPolicy(FieldGrowthPolicy policy);
64 FieldGrowthPolicy fieldGrowthPolicy() const;
65 void setRowWrapPolicy(RowWrapPolicy policy);
66 RowWrapPolicy rowWrapPolicy() const;
67 void setLabelAlignment(Qt::Alignment alignment);
68 Qt::Alignment labelAlignment() const;
69 void setFormAlignment(Qt::Alignment alignment);
70 Qt::Alignment formAlignment() const;
71
72 void setHorizontalSpacing(int spacing);
73 int horizontalSpacing() const;
74 void setVerticalSpacing(int spacing);
75 int verticalSpacing() const;
76
77 int spacing() const override;
78 void setSpacing(int) override;
79
80 void addRow(QWidget *label, QWidget *field);
81 void addRow(QWidget *label, QLayout *field);
82 void addRow(const QString &labelText, QWidget *field);
83 void addRow(const QString &labelText, QLayout *field);
84 void addRow(QWidget *widget);
85 void addRow(QLayout *layout);
86
87 void insertRow(int row, QWidget *label, QWidget *field);
88 void insertRow(int row, QWidget *label, QLayout *field);
89 void insertRow(int row, const QString &labelText, QWidget *field);
90 void insertRow(int row, const QString &labelText, QLayout *field);
91 void insertRow(int row, QWidget *widget);
92 void insertRow(int row, QLayout *layout);
93
94 void removeRow(int row);
95 void removeRow(QWidget *widget);
96 void removeRow(QLayout *layout);
97
98 TakeRowResult takeRow(int row);
99 TakeRowResult takeRow(QWidget *widget);
100 TakeRowResult takeRow(QLayout *layout);
101
102 void setItem(int row, ItemRole role, QLayoutItem *item);
103 void setWidget(int row, ItemRole role, QWidget *widget);
104 void setLayout(int row, ItemRole role, QLayout *layout);
105
106 void setRowVisible(int row, bool on);
107 void setRowVisible(QWidget *widget, bool on);
108 void setRowVisible(QLayout *layout, bool on);
109
110 bool isRowVisible(int row) const;
111 bool isRowVisible(QWidget *widget) const;
112 bool isRowVisible(QLayout *layout) const;
113
114 QLayoutItem *itemAt(int row, ItemRole role) const;
115 void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
116 void getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
117 void getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const;
118 QWidget *labelForField(QWidget *field) const;
119 QWidget *labelForField(QLayout *field) const;
120
121 // reimplemented from QLayout
122 void addItem(QLayoutItem *item) override;
123 QLayoutItem *itemAt(int index) const override;
124 QLayoutItem *takeAt(int index) override;
125
126 void setGeometry(const QRect &rect) override;
127 QSize minimumSize() const override;
128 QSize sizeHint() const override;
129 void invalidate() override;
130
131 bool hasHeightForWidth() const override;
132 int heightForWidth(int width) const override;
133 Qt::Orientations expandingDirections() const override;
134 int count() const override;
135
136 int rowCount() const;
137
138#if 0
139 void dump() const;
140#endif
141
142private:
143 void resetFieldGrowthPolicy();
144 void resetRowWrapPolicy();
145 void resetLabelAlignment();
146 void resetFormAlignment();
147};
148
149Q_DECLARE_TYPEINFO(QFormLayout::TakeRowResult, Q_PRIMITIVE_TYPE);
150
151QT_END_NAMESPACE
152
153#endif
void insertRows(int row, int count)
QList< QLayoutStruct > hfwLayouts
void arrangeWidgets(const QList< QLayoutStruct > &layouts, QRect &rect)
void setupVerticalLayoutData(int width)
QStyle * getStyle() const
QLayoutItem * replaceAt(int index, QLayoutItem *) override
Qt::Alignment labelAlignment
Qt::Alignment formAlignment
void setLayout(int row, QFormLayout::ItemRole role, QLayout *layout)
int insertRow(int row)
void removeRow(int row)
void recalcHFW(int w)
void setWidget(int row, QFormLayout::ItemRole role, QWidget *widget)
bool setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item)
QList< QLayoutStruct > vLayouts
void setupHorizontalLayoutData(int width)
bool haveHfwCached(int width) const
QList< QFormLayoutItem * > m_things
The QFormLayout class manages forms of input widgets and their associated labels.
Definition qformlayout.h:19
Definition qlist.h:80
\inmodule QtCore
Definition qsize.h:26
const T & operator()(int r, int c) const
static void storageIndexToPosition(int idx, int *rowPtr, int *colPtr)
const Storage & storage() const
T & operator()(int r, int c)
void insertRow(int r, const T &value)
static int storageIndexFromLayoutItem(const QFormLayoutPrivate::ItemMatrix &m, QFormLayoutItem *item)
static int spacingHelper(QWidget *parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem *item1, QFormLayoutItem *item2, QFormLayoutItem *prevItem1, QFormLayoutItem *prevItem2)
static Qt::Alignment fixedAlignment(Qt::Alignment alignment, Qt::LayoutDirection layoutDirection)
const uint DefaultFieldGrowthPolicy
static void updateFormLayoutItem(QFormLayoutItem *item, int userVSpacing, QFormLayout::FieldGrowthPolicy fieldGrowthPolicy, bool fullRow)
static void hideOrShowWidgetsInLayout(QLayout *layout, bool on)
static QLayoutItem * ownershipCleanedItem(QFormLayoutItem *item, QFormLayout *layout)
static void clearAndDestroyQLayoutItem(QLayoutItem *item)
static void initLayoutStruct(QLayoutStruct &sl, QFormLayoutItem *item)
const uint DefaultRowWrapPolicy
QT_REQUIRE_CONFIG(thread)
#define QWIDGETSIZE_MAX
Definition qwidget.h:922
Qt::Orientations expandingDirections() const
int heightForWidth(int width) const
QLayoutItem * item
QLayout * layout() const
bool hasHeightForWidth() const
QWidget * widget() const
void setGeometry(const QRect &r)
void setVisible(bool on)
QRect geometry() const
bool operator==(const QFormLayoutItem &other)
int vStretch() const
bool isHidden() const
int minimumHeightForWidth(int width) const
QFormLayoutItem(QLayoutItem *i)
QSizePolicy::ControlTypes controlTypes() const
void init(int stretchFactor=0, int minSize=0)