Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGridLayout Class

TheQGridLayout class lays out widgets in a grid.More...

Header:#include <QGridLayout>
Inherits:QLayout

Properties

Public Functions

QGridLayout(QWidget * parent)
QGridLayout()
~QGridLayout()
voidaddItem(QLayoutItem * item, int row, int column, int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = 0)
voidaddLayout(QLayout * layout, int row, int column, Qt::Alignment alignment = 0)
voidaddLayout(QLayout * layout, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)
voidaddWidget(QWidget * widget, int row, int column, Qt::Alignment alignment = 0)
voidaddWidget(QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)
QRectcellRect(int row, int column) const
intcolumnCount() const
intcolumnMinimumWidth(int column) const
intcolumnStretch(int column) const
voidgetItemPosition(int index, int * row, int * column, int * rowSpan, int * columnSpan)
inthorizontalSpacing() const
QLayoutItem *itemAtPosition(int row, int column) const
Qt::CorneroriginCorner() const
introwCount() const
introwMinimumHeight(int row) const
introwStretch(int row) const
voidsetColumnMinimumWidth(int column, int minSize)
voidsetColumnStretch(int column, int stretch)
voidsetHorizontalSpacing(int spacing)
voidsetOriginCorner(Qt::Corner corner)
voidsetRowMinimumHeight(int row, int minSize)
voidsetRowStretch(int row, int stretch)
voidsetSpacing(int spacing)
voidsetVerticalSpacing(int spacing)
intspacing() const
intverticalSpacing() const

Reimplemented Public Functions

virtual intcount() const
virtual Qt::OrientationsexpandingDirections() const
virtual boolhasHeightForWidth() const
virtual intheightForWidth(int w) const
virtual voidinvalidate()
virtual QLayoutItem *itemAt(int index) const
virtual QSizemaximumSize() const
virtual intminimumHeightForWidth(int w) const
virtual QSizeminimumSize() const
virtual voidsetGeometry(const QRect & rect)
virtual QSizesizeHint() const
virtual QLayoutItem *takeAt(int index)
  • 35 public functions inherited fromQLayout
  • 29 public functions inherited fromQObject
  • 17 public functions inherited fromQLayoutItem

Reimplemented Protected Functions

virtual voidaddItem(QLayoutItem * item)
  • 4 protected functions inherited fromQLayout
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 1 static public member inherited fromQLayout
  • 7 static public members inherited fromQObject
  • 4 protected functions inherited fromQLayout
  • 8 protected functions inherited fromQObject

Detailed Description

TheQGridLayout class lays out widgets in a grid.

QGridLayout takes the space made available to it (by its parent layout or by theparentWidget()), 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 usingsetColumnMinimumWidth() and the minimum width of each widget in that column. The stretch factor is set usingsetColumnStretch() 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 usingaddWidget(). It is also possible for a widget to occupy multiple cells using the row and column spanning overloads ofaddItem() andaddWidget(). 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, callremoveWidget(). CallingQWidget::hide() on a widget also effectively removes the widget from the layout untilQWidget::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 aQLabel, aQLineEdit, and aQListBox. Columns 1 and 3 are placeholders made withsetColumnMinimumWidth(). Row 0 consists of threeQLabel objects, row 1 of threeQLineEdit objects and row 2 of threeQListBox 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 usingsetColumnMinimumWidth() andsetColumnStretch().

If theQGridLayout 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 callingaddLayout() 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 usingaddWidget(),addItem(), andaddLayout().

QGridLayout also includes two margin widths: thecontents margin and thespacing(). The contents margin is the width of the reserved space along each of theQGridLayout's four sides. Thespacing() is the width of the automatically allocated spacing between neighboring boxes.

The default contents margin values are provided by thestyle. 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 alsoQBoxLayout,QStackedLayout,Layout Management, andBasic Layouts Example.

Property Documentation

horizontalSpacing :int

This property holds the spacing between widgets that are laid out side by side.

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.

This property was introduced in Qt 4.3.

Access functions:

inthorizontalSpacing() const
voidsetHorizontalSpacing(int spacing)

See alsoverticalSpacing,QStyle::pixelMetric(), andPM_LayoutHorizontalSpacing.

verticalSpacing :int

This property holds the spacing between widgets that are laid out on top of each other.

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.

This property was introduced in Qt 4.3.

Access functions:

intverticalSpacing() const
voidsetVerticalSpacing(int spacing)

See alsohorizontalSpacing,QStyle::pixelMetric(), andPM_LayoutHorizontalSpacing.

Member Function Documentation

QGridLayout::QGridLayout(QWidget * parent)

Constructs a newQGridLayout with parent widget,parent. The layout has one row and one column initially, and will expand when new items are inserted.

QGridLayout::QGridLayout()

Constructs a new grid layout.

You must insert this grid into another layout. You can insert widgets and layouts into this layout at any time, but laying out will not be performed before this is inserted into another layout.

QGridLayout::~QGridLayout()

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

The layout's widgets aren't destroyed.

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

Addsitem at positionrow,column, spanningrowSpan rows andcolumnSpan columns, and aligns it according toalignment. IfrowSpan and/orcolumnSpan is -1, then the item will extend to the bottom and/or right edge, respectively. The layout takes ownership of theitem.

Warning: Do not use this function to add child layouts or child widget items. UseaddLayout() oraddWidget() instead.

[virtual protected]void QGridLayout::addItem(QLayoutItem * item)

Reimplemented fromQLayout::addItem().

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

Places thelayout at position (row,column) in the grid. The top-left position is (0, 0).

The alignment is specified byalignment. 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 tosizeHint().

layout becomes a child of the grid layout.

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

This is an overloaded function.

This version adds the layoutlayout to the cell grid, spanning multiple rows/columns. The cell will start atrow,column spanningrowSpan rows andcolumnSpan columns.

IfrowSpan and/orcolumnSpan is -1, then the layout will extend to the bottom and/or right edge, respectively.

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

Adds the givenwidget to the cell grid atrow,column. The top-left position is (0, 0) by default.

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

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

This is an overloaded function.

This version adds the givenwidget to the cell grid, spanning multiple rows/columns. The cell will start atfromRow,fromColumn spanningrowSpan rows andcolumnSpan columns. Thewidget will have the givenalignment.

IfrowSpan and/orcolumnSpan is -1, then the widget will extend to the bottom and/or right edge, respectively.

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

Returns the geometry of the cell with rowrow and columncolumn in the grid. Returns an invalid rectangle ifrow orcolumn is outside the grid.

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

int QGridLayout::columnCount() const

Returns the number of columns in this grid.

int QGridLayout::columnMinimumWidth(int column) const

Returns the column spacing for columncolumn.

See alsosetColumnMinimumWidth().

int QGridLayout::columnStretch(int column) const

Returns the stretch factor for columncolumn.

See alsosetColumnStretch().

[virtual]int QGridLayout::count() const

Reimplemented fromQLayout::count().

[virtual]Qt::Orientations QGridLayout::expandingDirections() const

Reimplemented fromQLayoutItem::expandingDirections().

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

Returns the position information of the item with the givenindex.

The variables passed asrow andcolumn are updated with the position of the item in the layout, and therowSpan andcolumnSpan variables are updated with the vertical and horizontal spans of the item.

See alsoitemAtPosition() anditemAt().

[virtual]bool QGridLayout::hasHeightForWidth() const

Reimplemented fromQLayoutItem::hasHeightForWidth().

[virtual]int QGridLayout::heightForWidth(int w) const

Reimplemented fromQLayoutItem::heightForWidth().

[virtual]void QGridLayout::invalidate()

Reimplemented fromQLayoutItem::invalidate().

[virtual]QLayoutItem * QGridLayout::itemAt(int index) const

Reimplemented fromQLayout::itemAt().

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

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

This function was introduced in Qt 4.4.

See alsogetItemPosition() andindexOf().

[virtual]QSize QGridLayout::maximumSize() const

Reimplemented fromQLayoutItem::maximumSize().

[virtual]int QGridLayout::minimumHeightForWidth(int w) const

Reimplemented fromQLayoutItem::minimumHeightForWidth().

[virtual]QSize QGridLayout::minimumSize() const

Reimplemented fromQLayoutItem::minimumSize().

Qt::Corner QGridLayout::originCorner() const

Returns the corner that's used for the grid's origin, i.e. for position (0, 0).

See alsosetOriginCorner().

int QGridLayout::rowCount() const

Returns the number of rows in this grid.

int QGridLayout::rowMinimumHeight(int row) const

Returns the minimum width set for rowrow.

See alsosetRowMinimumHeight().

int QGridLayout::rowStretch(int row) const

Returns the stretch factor for rowrow.

See alsosetRowStretch().

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

Sets the minimum width of columncolumn tominSize pixels.

See alsocolumnMinimumWidth() andsetRowMinimumHeight().

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

Sets the stretch factor of columncolumn tostretch. 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 usingaddItem() with aQSpacerItem.

See alsocolumnStretch() andsetRowStretch().

[virtual]void QGridLayout::setGeometry(constQRect & rect)

Reimplemented fromQLayoutItem::setGeometry().

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

Sets the grid's origin corner, i.e. position (0, 0), tocorner.

See alsooriginCorner().

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

Sets the minimum height of rowrow tominSize pixels.

See alsorowMinimumHeight() andsetColumnMinimumWidth().

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

Sets the stretch factor of rowrow tostretch. 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 alsorowStretch(),setRowMinimumHeight(), andsetColumnStretch().

void QGridLayout::setSpacing(int spacing)

This function sets both the vertical and horizontal spacing tospacing.

See alsospacing(),setVerticalSpacing(), andsetHorizontalSpacing().

[virtual]QSize QGridLayout::sizeHint() const

Reimplemented fromQLayoutItem::sizeHint().

int QGridLayout::spacing() const

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

See alsosetSpacing(),verticalSpacing(), andhorizontalSpacing().

[virtual]QLayoutItem * QGridLayout::takeAt(int index)

Reimplemented fromQLayout::takeAt().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp