Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QGridLayout Class Reference

The QGridLayout class lays out widgets in a grid. More...

#include <qgridlayout.h>

+ Inheritance diagram for QGridLayout:
+ Collaboration diagram for QGridLayout:

Public Member Functions

 QGridLayout (QWidget *parent=nullptr)
 Constructs a new QGridLayout with parent widget, parent.
 
 ~QGridLayout ()
 Destroys the grid layout.
 
QSize sizeHint () const override
 \reimp
 
QSize minimumSize () const override
 \reimp
 
QSize maximumSize () const override
 \reimp
 
void setHorizontalSpacing (int spacing)
 
int horizontalSpacing () const
 the spacing between widgets that are laid out side by side
 
void setVerticalSpacing (int spacing)
 
int verticalSpacing () const
 the spacing between widgets that are laid out on top of each other
 
void setSpacing (int spacing) override
 This function sets both the vertical and horizontal spacing to spacing.
 
int spacing () const override
 If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it return -1.
 
void setRowStretch (int row, int stretch)
 Sets the stretch factor of row row to stretch.
 
void setColumnStretch (int column, int stretch)
 Sets the stretch factor of column column to stretch.
 
int rowStretch (int row) const
 Returns the stretch factor for row row.
 
int columnStretch (int column) const
 Returns the stretch factor for column column.
 
void setRowMinimumHeight (int row, int minSize)
 Sets the minimum height of row row to minSize pixels.
 
void setColumnMinimumWidth (int column, int minSize)
 Sets the minimum width of column column to minSize pixels.
 
int rowMinimumHeight (int row) const
 Returns the minimum width set for row row.
 
int columnMinimumWidth (int column) const
 Returns the column spacing for column column.
 
int columnCount () const
 Returns the number of columns in this grid.
 
int rowCount () const
 Returns the number of rows in this grid.
 
QRect cellRect (int row, int column) const
 Returns the geometry of the cell with row row and column column in the grid.
 
bool hasHeightForWidth () const override
 \reimp
 
int heightForWidth (int) const override
 \reimp
 
int minimumHeightForWidth (int) const override
 \reimp
 
Qt::Orientations expandingDirections () const override
 \reimp
 
void invalidate () override
 \reimp
 
void addWidget (QWidget *w)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void addWidget (QWidget *, int row, int column, Qt::Alignment=Qt::Alignment())
 Adds the given widget to the cell grid at row, column.
 
void addWidget (QWidget *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment=Qt::Alignment())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version adds the given widget to the cell grid, spanning multiple rows/columns.
 
void addLayout (QLayout *, int row, int column, Qt::Alignment=Qt::Alignment())
 Places the layout at position (row, column) in the grid.
 
void addLayout (QLayout *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment=Qt::Alignment())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version adds the layout layout to the cell grid, spanning multiple rows/columns.
 
void setOriginCorner (Qt::Corner)
 Sets the grid's origin corner, i.e.
 
Qt::Corner originCorner () const
 Returns the corner that's used for the grid's origin, i.e.
 
QLayoutItemitemAt (int index) const override
 \reimp
 
QLayoutItemitemAtPosition (int row, int column) const
 
QLayoutItemtakeAt (int index) override
 \reimp
 
int count () const override
 \reimp
 
void setGeometry (const QRect &) override
 \reimp
 
void addItem (QLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, Qt::Alignment=Qt::Alignment())
 Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it according to alignment.
 
void setDefaultPositioning (int n, Qt::Orientation orient)
 
void getItemPosition (int idx, int *row, int *column, int *rowSpan, int *columnSpan) const
 Returns the position information of the item with the given index.
 
- Public Member Functions inherited from QLayout
 QLayout (QWidget *parent=nullptr)
 Constructs a new top-level QLayout, with parent parent.
 
 ~QLayout ()
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContentsMargins (const QMargins &margins)
 
void unsetContentsMargins ()
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
bool setAlignment (QWidget *w, Qt::Alignment alignment)
 Sets the alignment for widget w to alignment and returns true if w is found in this layout (not including child layouts); otherwise returns false.
 
bool setAlignment (QLayout *l, Qt::Alignment alignment)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the alignment for the layout l to alignment and returns true if l is found in this layout (not including child layouts); otherwise returns false.
 
void setSizeConstraint (SizeConstraint)
 
SizeConstraint sizeConstraint () const
 
void setMenuBar (QWidget *w)
 Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins().
 
QWidgetmenuBar () const
 Returns the menu bar set for this layout, or \nullptr if no menu bar is set.
 
QWidgetparentWidget () const
 Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget.
 
void invalidate () override
 \reimp
 
QRect geometry () const override
 \reimp
 
bool activate ()
 Redoes the layout for parentWidget() if necessary.
 
void update ()
 Updates the layout for parentWidget().
 
void addWidget (QWidget *w)
 Adds widget w to this layout in a manner specific to the layout.
 
void removeWidget (QWidget *w)
 Removes the widget widget from the layout.
 
void removeItem (QLayoutItem *)
 Removes the layout item item from the layout.
 
Qt::Orientations expandingDirections () const override
 Returns whether this layout can make use of more space than sizeHint().
 
QSize minimumSize () const override
 Returns the minimum size of this layout.
 
QSize maximumSize () const override
 Returns the maximum size of this layout.
 
virtual int indexOf (const QWidget *) const
 Searches for widget widget in this layout (not including child layouts).
 
virtual int indexOf (const QLayoutItem *) const
 
bool isEmpty () const override
 \reimp
 
QSizePolicy::ControlTypes controlTypes () const override
 \reimp
 
virtual QLayoutItemreplaceWidget (QWidget *from, QWidget *to, Qt::FindChildOptions options=Qt::FindChildrenRecursively)
 
int totalMinimumHeightForWidth (int w) const
 
int totalHeightForWidth (int w) const
 
QSize totalMinimumSize () const
 
QSize totalMaximumSize () const
 
QSize totalSizeHint () const
 
QLayoutlayout () override
 \reimp
 
void setEnabled (bool)
 Enables this layout if enable is true, otherwise disables it.
 
bool isEnabled () const
 Returns true if the layout is enabled; otherwise returns false.
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 
- Public Member Functions inherited from QLayoutItem
 QLayoutItem (Qt::Alignment alignment=Qt::Alignment())
 Constructs a layout item with an alignment.
 
virtual ~QLayoutItem ()
 Destroys the QLayoutItem.
 
virtual QWidgetwidget () const
 If this item manages a QWidget, returns that widget.
 
virtual QSpacerItemspacerItem ()
 If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise \nullptr is returned.
 
Qt::Alignment alignment () const
 Returns the alignment of this item.
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment.
 

Protected Member Functions

void addItem (QLayoutItem *) override
 \reimp
 
- Protected Member Functions inherited from QLayout
void widgetEvent (QEvent *)
 
void childEvent (QChildEvent *e) override
 \reimp
 
void addChildLayout (QLayout *l)
 This function is called from addLayout() or insertLayout() functions in subclasses to add layout childLayout as a sub-layout.
 
void addChildWidget (QWidget *w)
 This function is called from addWidget() functions in subclasses to add w as a managed widget of a layout.
 
bool adoptLayout (QLayout *layout)
 
QRect alignmentRect (const QRect &) const
 Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment().
 
 QLayout (QLayoutPrivate &d, QLayout *, QWidget *)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Additional Inherited Members

- Public Types inherited from QLayout
enum  SizeConstraint {
  SetDefaultConstraint , SetNoConstraint , SetMinimumSize , SetFixedSize ,
  SetMaximumSize , SetMinAndMaxSize
}
 The possible values are: More...
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 
- Static Public Member Functions inherited from QLayout
static QSize closestAcceptableSize (const QWidget *w, const QSize &s)
 Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QLayoutItem
Qt::Alignment align
 
- Properties inherited from QLayout
int spacing
 the spacing between widgets inside the layout
 
QMargins contentsMargins
 
SizeConstraint sizeConstraint
 the resize mode of the layout
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

The QGridLayout class lays out widgets in a grid.

\inmodule QtWidgets

QGridLayout takes the space made available to it (by its parent layout or by the parentWidget()), divides it up into rows and columns, and puts each widget it manages into the correct cell.

Columns and rows behave identically; we will discuss columns, but there are equivalent functions for rows.

Each column has a minimum width and a stretch factor. The minimum width is the greatest of that set using setColumnMinimumWidth() and the minimum width of each widget in that column. The stretch factor is set using setColumnStretch() and determines how much of the available space the column will get over and above its necessary minimum.

Normally, each managed widget or layout is put into a cell of its own using addWidget(). It is also possible for a widget to occupy multiple cells using the row and column spanning overloads of addItem() and addWidget(). If you do this, QGridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors).

To remove a widget from a layout, call removeWidget(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

This illustration shows a fragment of a dialog with a five-column, three-row grid (the grid is shown overlaid in magenta):

A grid layout

Columns 0, 2 and 4 in this dialog fragment are made up of a QLabel, a QLineEdit, and a QListBox. Columns 1 and 3 are placeholders made with setColumnMinimumWidth(). Row 0 consists of three QLabel objects, row 1 of three QLineEdit objects and row 2 of three QListBox objects. We used placeholder columns (1 and 3) to get the right amount of space between the columns.

Note that the columns and rows are not equally wide or tall. If you want two columns to have the same width, you must set their minimum widths and stretch factors to be the same yourself. You do this using setColumnMinimumWidth() and setColumnStretch().

If the QGridLayout is not the top-level layout (i.e. does not manage all of the widget's area and children), you must add it to its parent layout when you create it, but before you do anything with it. The normal way to add a layout is by calling addLayout() on the parent layout.

Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addItem(), and addLayout().

QGridLayout also includes two margin widths: the \l{getContentsMargins()}{contents margin} and the spacing(). The contents margin is the width of the reserved space along each of the QGridLayout's four sides. The spacing() is the width of the automatically allocated spacing between neighboring boxes.

The default contents margin values are provided by the \l{QStyle::pixelMetric()}{style}. The default value Qt styles specify is 9 for child widgets and 11 for windows. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.

See also
QBoxLayout, QStackedLayout, {Layout Management}, {Basic Layouts Example}

Definition at line 20 of file qgridlayout.h.

Constructor & Destructor Documentation

◆ QGridLayout()

QGridLayout::QGridLayout ( QWidget * parent = nullptr)
explicit

Constructs a new QGridLayout with parent widget, parent.

The layout has one row and one column initially, and will expand when new items are inserted.

The layout is set directly as the top-level layout for parent. There can be only one top-level layout for a widget. It is returned by QWidget::layout().

If parent is \nullptr, then you must insert this grid layout into another layout, or set it as a widget's layout using QWidget::setLayout().

See also
QWidget::setLayout()

Definition at line 1050 of file qgridlayout.cpp.

References d.

◆ ~QGridLayout()

QGridLayout::~QGridLayout ( )

Destroys the grid layout.

Geometry management is terminated if this is a top-level grid.

The layout's widgets aren't destroyed.

Definition at line 1085 of file qgridlayout.cpp.

References d.

Member Function Documentation

◆ addItem() [1/2]

void QGridLayout::addItem ( QLayoutItem * item)
overrideprotectedvirtual

\reimp

Implements QLayout.

Definition at line 1364 of file qgridlayout.cpp.

References addItem(), d, and item.

+ Here is the call graph for this function:

◆ addItem() [2/2]

void QGridLayout::addItem ( QLayoutItem * item,
int row,
int column,
int rowSpan = 1,
int columnSpan = 1,
Qt::Alignment alignment = Qt::Alignment() )

Adds item at position row, column, spanning rowSpan rows and columnSpan columns, and aligns it according to alignment.

If rowSpan and/or columnSpan is -1, then the item will extend to the bottom and/or right edge, respectively. The layout takes ownership of the item.

Warning
Do not use this function to add child layouts or child widget items. Use addLayout() or addWidget() instead.

Definition at line 1382 of file qgridlayout.cpp.

References QLayoutItem::alignment(), d, invalidate(), and item.

Referenced by addItem(), addWidget(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addLayout() [1/2]

void QGridLayout::addLayout ( QLayout * layout,
int row,
int column,
int rowSpan,
int columnSpan,
Qt::Alignment alignment = Qt::Alignment() )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version adds the layout layout to the cell grid, spanning multiple rows/columns.

The cell will start at row, column spanning rowSpan rows and columnSpan columns.

If rowSpan and/or columnSpan is -1, then the layout will extend to the bottom and/or right edge, respectively.

Definition at line 1484 of file qgridlayout.cpp.

References QLayout::adoptLayout(), QLayoutItem::alignment(), d, and QLayout::layout().

+ Here is the call graph for this function:

◆ addLayout() [2/2]

void QGridLayout::addLayout ( QLayout * layout,
int row,
int column,
Qt::Alignment alignment = Qt::Alignment() )

Places the layout at position (row, column) in the grid.

The top-left position is (0, 0).

The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.

A non-zero alignment indicates that the layout should not grow to fill the available space but should be sized according to sizeHint().

layout becomes a child of the grid layout.

Definition at line 1463 of file qgridlayout.cpp.

References QLayout::adoptLayout(), QLayoutItem::alignment(), d, and QLayout::layout().

Referenced by QWizardPrivate::recreateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addWidget() [1/3]

void QGridLayout::addWidget ( QWidget * widget,
int fromRow,
int fromColumn,
int rowSpan,
int columnSpan,
Qt::Alignment alignment = Qt::Alignment() )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version adds the given widget to the cell grid, spanning multiple rows/columns.

The cell will start at fromRow, fromColumn spanning rowSpan rows and columnSpan columns. The widget will have the given alignment.

If rowSpan and/or columnSpan is -1, then the widget will extend to the bottom and/or right edge, respectively.

Definition at line 1427 of file qgridlayout.cpp.

References QLayout::addChildWidget(), QLayoutItem::alignment(), d, invalidate(), and QLayoutItem::widget().

+ Here is the call graph for this function:

◆ addWidget() [2/3]

void QGridLayout::addWidget ( QWidget * widget,
int row,
int column,
Qt::Alignment alignment = Qt::Alignment() )

Adds the given widget to the cell grid at row, column.

The top-left position is (0, 0) by default.

The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell.

Definition at line 1399 of file qgridlayout.cpp.

References QLayout::addChildWidget(), addItem(), QLayoutItem::alignment(), className, QLayoutPrivate::createWidgetItem(), d, metaObject(), QObject::objectName, Q_UNLIKELY, qWarning, toLocal8Bit(), and QLayoutItem::widget().

+ Here is the call graph for this function:

◆ addWidget() [3/3]

void QGridLayout::addWidget ( QWidget * widget)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 64 of file qgridlayout.h.

References QLayout::addWidget().

Referenced by ButtonWidget::ButtonWidget(), QtPrivate::QColorShower::QColorShower(), QErrorMessage::QErrorMessage(), QWizardHeader::QWizardHeader(), ScreenWidget::ScreenWidget(), QWizardPrivate::recreateLayout(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cellRect()

QRect QGridLayout::cellRect ( int row,
int column ) const

Returns the geometry of the cell with row row and column column in the grid.

Returns an invalid rectangle if row or column is outside the grid.

Warning
in the current version of Qt this function does not return valid results until setGeometry() has been called, i.e. after the parentWidget() is visible.

Definition at line 1355 of file qgridlayout.cpp.

References d.

◆ columnCount()

int QGridLayout::columnCount ( ) const

Returns the number of columns in this grid.

Definition at line 1188 of file qgridlayout.cpp.

References d.

Referenced by QWizardPrivate::recreateLayout(), and QMessageBoxPrivate::setupLayout().

+ Here is the caller graph for this function:

◆ columnMinimumWidth()

int QGridLayout::columnMinimumWidth ( int column) const

Returns the column spacing for column column.

See also
setColumnMinimumWidth()

Definition at line 1605 of file qgridlayout.cpp.

References d.

◆ columnStretch()

int QGridLayout::columnStretch ( int column) const

Returns the stretch factor for column column.

See also
setColumnStretch()

Definition at line 1533 of file qgridlayout.cpp.

References d.

◆ count()

int QGridLayout::count ( ) const
overridevirtual

\reimp

Implements QLayout.

Definition at line 1270 of file qgridlayout.cpp.

References d.

Referenced by QWizardPrivate::recreateLayout().

+ Here is the caller graph for this function:

◆ expandingDirections()

Qt::Orientations QGridLayout::expandingDirections ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Definition at line 1614 of file qgridlayout.cpp.

References d, horizontalSpacing(), and verticalSpacing().

+ Here is the call graph for this function:

◆ getItemPosition()

void QGridLayout::getItemPosition ( int index,
int * row,
int * column,
int * rowSpan,
int * columnSpan ) const

Returns the position information of the item with the given index.

The variables passed as row and column are updated with the position of the item in the layout, and the rowSpan and columnSpan variables are updated with the vertical and horizontal spans of the item.

See also
itemAtPosition(), itemAt()

Definition at line 1326 of file qgridlayout.cpp.

References d.

◆ hasHeightForWidth()

bool QGridLayout::hasHeightForWidth ( ) const
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 1242 of file qgridlayout.cpp.

References hasHeightForWidth(), horizontalSpacing(), and verticalSpacing().

Referenced by hasHeightForWidth().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ heightForWidth()

int QGridLayout::heightForWidth ( int w) const
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 1250 of file qgridlayout.cpp.

References d, QGridLayoutPrivate::heightForWidth(), horizontalSpacing(), and verticalSpacing().

+ Here is the call graph for this function:

◆ horizontalSpacing()

int QGridLayout::horizontalSpacing ( ) const

the spacing between widgets that are laid out side by side

Since
4.3

If no value is explicitly set, the layout's horizontal spacing is inherited from the parent layout, or from the style settings for the parent widget.

See also
verticalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}

Definition at line 1109 of file qgridlayout.cpp.

References d, QStyle::PM_LayoutHorizontalSpacing, and qSmartSpacing().

Referenced by expandingDirections(), hasHeightForWidth(), heightForWidth(), maximumSize(), minimumHeightForWidth(), minimumSize(), setGeometry(), sizeHint(), and spacing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ invalidate()

void QGridLayout::invalidate ( )
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 1647 of file qgridlayout.cpp.

References d, and QLayout::invalidate().

Referenced by addItem(), addWidget(), setColumnMinimumWidth(), setColumnStretch(), setHorizontalSpacing(), setRowMinimumHeight(), setRowStretch(), setSpacing(), and setVerticalSpacing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ itemAt()

QLayoutItem * QGridLayout::itemAt ( int index) const
overridevirtual

\reimp

Implements QLayout.

Definition at line 1280 of file qgridlayout.cpp.

References d.

◆ itemAtPosition()

QLayoutItem * QGridLayout::itemAtPosition ( int row,
int column ) const
Since
4.4

Returns the layout item that occupies cell (row, column), or \nullptr if the cell is empty.

See also
getItemPosition(), indexOf()

Definition at line 1294 of file qgridlayout.cpp.

References d, i, and QGridBox::item().

+ Here is the call graph for this function:

◆ maximumSize()

QSize QGridLayout::maximumSize ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Definition at line 1223 of file qgridlayout.cpp.

References Qt::AlignHorizontal_Mask, QLayoutItem::alignment(), Qt::AlignVertical_Mask, d, horizontalSpacing(), QLAYOUTSIZE_MAX, and verticalSpacing().

+ Here is the call graph for this function:

◆ minimumHeightForWidth()

int QGridLayout::minimumHeightForWidth ( int w) const
overridevirtual

\reimp

Reimplemented from QLayoutItem.

Definition at line 1260 of file qgridlayout.cpp.

References d, horizontalSpacing(), QGridLayoutPrivate::minimumHeightForWidth(), and verticalSpacing().

+ Here is the call graph for this function:

◆ minimumSize()

QSize QGridLayout::minimumSize ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Definition at line 1210 of file qgridlayout.cpp.

References d, horizontalSpacing(), and verticalSpacing().

+ Here is the call graph for this function:

◆ originCorner()

Qt::Corner QGridLayout::originCorner ( ) const

Returns the corner that's used for the grid's origin, i.e.

for position (0, 0).

Definition at line 1634 of file qgridlayout.cpp.

References Qt::BottomLeftCorner, Qt::BottomRightCorner, d, Qt::TopLeftCorner, and Qt::TopRightCorner.

◆ rowCount()

int QGridLayout::rowCount ( ) const

Returns the number of rows in this grid.

Definition at line 1179 of file qgridlayout.cpp.

References d.

Referenced by QWizardPrivate::recreateLayout(), and QMessageBoxPrivate::setupLayout().

+ Here is the caller graph for this function:

◆ rowMinimumHeight()

int QGridLayout::rowMinimumHeight ( int row) const

Returns the minimum width set for row row.

See also
setRowMinimumHeight()

Definition at line 1582 of file qgridlayout.cpp.

References d.

◆ rowStretch()

int QGridLayout::rowStretch ( int row) const

Returns the stretch factor for row row.

See also
setRowStretch()

Definition at line 1522 of file qgridlayout.cpp.

References d.

◆ setColumnMinimumWidth()

void QGridLayout::setColumnMinimumWidth ( int column,
int minSize )

Sets the minimum width of column column to minSize pixels.

See also
columnMinimumWidth(), setRowMinimumHeight()

Definition at line 1593 of file qgridlayout.cpp.

References d, and invalidate().

Referenced by QWizardHeader::QWizardHeader(), QWizardPrivate::recreateLayout(), and QWizardHeader::setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setColumnStretch()

void QGridLayout::setColumnStretch ( int column,
int stretch )

Sets the stretch factor of column column to stretch.

The first column is number 0.

The stretch factor is relative to the other columns in this grid. Columns with a higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other column in this table can grow at all, the column may still grow.

An alternative approach is to add spacing using addItem() with a QSpacerItem.

See also
columnStretch(), setRowStretch()

Definition at line 1556 of file qgridlayout.cpp.

References d, and invalidate().

Referenced by QErrorMessage::QErrorMessage(), and QWizardHeader::QWizardHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDefaultPositioning()

void QGridLayout::setDefaultPositioning ( int n,
Qt::Orientation orient )

(mostly)

Sets the positioning mode used by addItem(). If orient is Qt::Horizontal, this layout is expanded to n columns, and items will be added columns-first. Otherwise it is expanded to n rows and items will be added rows-first.

Definition at line 1066 of file qgridlayout.cpp.

References d, and Qt::Horizontal.

◆ setGeometry()

void QGridLayout::setGeometry ( const QRect & rect)
overridevirtual

\reimp

Reimplemented from QLayout.

Definition at line 1336 of file qgridlayout.cpp.

References QLayoutItem::alignment(), QLayout::alignmentRect(), d, QLayout::geometry(), horizontalSpacing(), rect, QLayout::setGeometry(), and verticalSpacing().

+ Here is the call graph for this function:

◆ setHorizontalSpacing()

void QGridLayout::setHorizontalSpacing ( int spacing)

Definition at line 1102 of file qgridlayout.cpp.

References d, invalidate(), and spacing().

Referenced by QWizardPrivate::recreateLayout(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOriginCorner()

void QGridLayout::setOriginCorner ( Qt::Corner corner)

Sets the grid's origin corner, i.e.

position (0, 0), to corner.

Definition at line 1623 of file qgridlayout.cpp.

References Qt::BottomLeftCorner, Qt::BottomRightCorner, d, and Qt::TopRightCorner.

◆ setRowMinimumHeight()

void QGridLayout::setRowMinimumHeight ( int row,
int minSize )

Sets the minimum height of row row to minSize pixels.

See also
rowMinimumHeight(), setColumnMinimumWidth()

Definition at line 1570 of file qgridlayout.cpp.

References d, and invalidate().

Referenced by QWizardHeader::QWizardHeader(), QWizardPrivate::recreateLayout(), QWizardHeader::setup(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRowStretch()

void QGridLayout::setRowStretch ( int row,
int stretch )

Sets the stretch factor of row row to stretch.

The first row is number 0.

The stretch factor is relative to the other rows in this grid. Rows with a higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other row in this table can grow at all, the row may still grow.

See also
rowStretch(), setRowMinimumHeight(), setColumnStretch()

Definition at line 1510 of file qgridlayout.cpp.

References d, and invalidate().

Referenced by QErrorMessage::QErrorMessage(), QWizardHeader::QWizardHeader(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSpacing()

void QGridLayout::setSpacing ( int spacing)
overridevirtual

This function sets both the vertical and horizontal spacing to spacing.

See also
setVerticalSpacing(), setHorizontalSpacing()

Reimplemented from QLayout.

Definition at line 1153 of file qgridlayout.cpp.

References d, invalidate(), and spacing().

Referenced by QWizardHeader::QWizardHeader(), and QWizardPrivate::recreateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setVerticalSpacing()

void QGridLayout::setVerticalSpacing ( int spacing)

Definition at line 1130 of file qgridlayout.cpp.

References d, invalidate(), and spacing().

Referenced by QWizardPrivate::recreateLayout(), and QMessageBoxPrivate::setupLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeHint()

QSize QGridLayout::sizeHint ( ) const
overridevirtual

\reimp

Implements QLayoutItem.

Definition at line 1197 of file qgridlayout.cpp.

References d, horizontalSpacing(), and verticalSpacing().

+ Here is the call graph for this function:

◆ spacing()

int QGridLayout::spacing ( ) const
overridevirtual

If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it return -1.

See also
setSpacing(), verticalSpacing(), horizontalSpacing()

Reimplemented from QLayout.

Definition at line 1166 of file qgridlayout.cpp.

References horizontalSpacing(), and verticalSpacing().

Referenced by QtPrivate::QColorShower::QColorShower(), setHorizontalSpacing(), setSpacing(), and setVerticalSpacing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ takeAt()

QLayoutItem * QGridLayout::takeAt ( int index)
overridevirtual

\reimp

Implements QLayout.

Definition at line 1311 of file qgridlayout.cpp.

References d.

Referenced by QWizardPrivate::recreateLayout().

+ Here is the caller graph for this function:

◆ verticalSpacing()

int QGridLayout::verticalSpacing ( ) const

the spacing between widgets that are laid out on top of each other

Since
4.3

If no value is explicitly set, the layout's vertical spacing is inherited from the parent layout, or from the style settings for the parent widget.

See also
horizontalSpacing, QStyle::pixelMetric(), {QStyle::}{PM_LayoutHorizontalSpacing}

Definition at line 1137 of file qgridlayout.cpp.

References d, QStyle::PM_LayoutVerticalSpacing, and qSmartSpacing().

Referenced by expandingDirections(), hasHeightForWidth(), heightForWidth(), maximumSize(), minimumHeightForWidth(), minimumSize(), setGeometry(), sizeHint(), and spacing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: