
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.More...
| Header: | #include <QGraphicsGridLayout> |
| Since: | Qt 4.4 |
| Inherits: | QGraphicsLayout |
| QGraphicsGridLayout(QGraphicsLayoutItem * parent = 0) | |
| virtual | ~QGraphicsGridLayout() |
| void | addItem(QGraphicsLayoutItem * item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = 0) |
| void | addItem(QGraphicsLayoutItem * item, int row, int column, Qt::Alignment alignment = 0) |
| Qt::Alignment | alignment(QGraphicsLayoutItem * item) const |
| Qt::Alignment | columnAlignment(int column) const |
| int | columnCount() const |
| qreal | columnMaximumWidth(int column) const |
| qreal | columnMinimumWidth(int column) const |
| qreal | columnPreferredWidth(int column) const |
| qreal | columnSpacing(int column) const |
| int | columnStretchFactor(int column) const |
| qreal | horizontalSpacing() const |
| QGraphicsLayoutItem * | itemAt(int row, int column) const |
| void | removeItem(QGraphicsLayoutItem * item) |
| Qt::Alignment | rowAlignment(int row) const |
| int | rowCount() const |
| qreal | rowMaximumHeight(int row) const |
| qreal | rowMinimumHeight(int row) const |
| qreal | rowPreferredHeight(int row) const |
| qreal | rowSpacing(int row) const |
| int | rowStretchFactor(int row) const |
| void | setAlignment(QGraphicsLayoutItem * item, Qt::Alignment alignment) |
| void | setColumnAlignment(int column, Qt::Alignment alignment) |
| void | setColumnFixedWidth(int column, qreal width) |
| void | setColumnMaximumWidth(int column, qreal width) |
| void | setColumnMinimumWidth(int column, qreal width) |
| void | setColumnPreferredWidth(int column, qreal width) |
| void | setColumnSpacing(int column, qreal spacing) |
| void | setColumnStretchFactor(int column, int stretch) |
| void | setHorizontalSpacing(qreal spacing) |
| void | setRowAlignment(int row, Qt::Alignment alignment) |
| void | setRowFixedHeight(int row, qreal height) |
| void | setRowMaximumHeight(int row, qreal height) |
| void | setRowMinimumHeight(int row, qreal height) |
| void | setRowPreferredHeight(int row, qreal height) |
| void | setRowSpacing(int row, qreal spacing) |
| void | setRowStretchFactor(int row, int stretch) |
| void | setSpacing(qreal spacing) |
| void | setVerticalSpacing(qreal spacing) |
| qreal | verticalSpacing() const |
| virtual int | count() const |
| virtual void | invalidate() |
| virtual QGraphicsLayoutItem * | itemAt(int index) const |
| virtual void | removeAt(int index) |
| virtual void | setGeometry(const QRectF & rect) |
| virtual QSizeF | sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const |
TheQGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.
The most common way to useQGraphicsGridLayout is to construct an object on the heap with no parent, add widgets and layouts by callingaddItem(), and finally assign the layout to a widget by callingQGraphicsWidget::setLayout().QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.
QGraphicsScene scene;QGraphicsWidget*textEdit= scene.addWidget(newQTextEdit);QGraphicsWidget*pushButton= scene.addWidget(newQPushButton);QGraphicsGridLayout*layout=newQGraphicsGridLayout;layout->addItem(textEdit,0,0);layout->addItem(pushButton,0,1);QGraphicsWidget*form=newQGraphicsWidget;form->setLayout(layout);scene.addItem(form);
The layout takes ownership of the items. In some cases when the layout item also inherits fromQGraphicsItem (such asQGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation ofQGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by callingcount() anditemAt(). CallingremoveAt() will remove an item from the layout, without destroying it.
QGraphicsGridLayout respects each item's size hints and size policies, and when a cell in the grid has more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by callingsetAlignment(), and check the alignment for any item by callingalignment(). You can also set the alignment for an entire row or column by callingsetRowAlignment() andsetColumnAlignment() respectively. By default, items are aligned to the top left.
See alsoQGraphicsLinearLayout andQGraphicsWidget.
Constructs aQGraphicsGridLayout instance.parent is passed toQGraphicsLayout's constructor.
[virtual]QGraphicsGridLayout::~QGraphicsGridLayout()Destroys theQGraphicsGridLayout object.
Addsitem to the grid onrow andcolumn. You can specify arowSpan andcolumnSpan and an optionalalignment.
Addsitem to the grid onrow andcolumn. You can specify an optionalalignment foritem.
Returns the alignment foritem.
See alsosetAlignment().
Returns the alignment forcolumn.
See alsosetColumnAlignment().
Returns the number of columns in the grid layout. This is always one more than the index of the last column that is occupied by a layout item (empty columns are counted except for those at the end).
Returns the maximum width forcolumn.
See alsosetColumnMaximumWidth().
Returns the minimum width forcolumn.
See alsosetColumnMinimumWidth().
Returns the preferred width forcolumn.
See alsosetColumnPreferredWidth().
Returns the column spacing forcolumn.
See alsosetColumnSpacing().
Returns the stretch factor forcolumn.
See alsosetColumnStretchFactor().
[virtual]int QGraphicsGridLayout::count() constReimplemented fromQGraphicsLayout::count().
Returns the number of layout items in this grid layout.
Returns the default horizontal spacing for the grid layout.
See alsosetHorizontalSpacing().
[virtual]void QGraphicsGridLayout::invalidate()Reimplemented fromQGraphicsLayout::invalidate().
Returns a pointer to the layout item at (row,column).
[virtual]QGraphicsLayoutItem * QGraphicsGridLayout::itemAt(int index) constReimplemented fromQGraphicsLayout::itemAt().
Returns the layout item atindex, or 0 if there is no layout item at this index.
[virtual]void QGraphicsGridLayout::removeAt(int index)Reimplemented fromQGraphicsLayout::removeAt().
Removes the layout item atindex without destroying it. Ownership of the item is transferred to the caller.
See alsoaddItem().
Removes the layout itemitem without destroying it. Ownership of the item is transferred to the caller.
This function was introduced in Qt 4.8.
See alsoaddItem().
Returns the alignment ofrow.
See alsosetRowAlignment().
Returns the number of rows in the grid layout. This is always one more than the index of the last row that is occupied by a layout item (empty rows are counted except for those at the end).
Returns the maximum height for row,row.
See alsosetRowMaximumHeight().
Returns the minimum height for row,row.
See alsosetRowMinimumHeight().
Returns the preferred height for row,row.
See alsosetRowPreferredHeight().
Returns the row spacing forrow.
See alsosetRowSpacing().
Returns the stretch factor forrow.
See alsosetRowStretchFactor().
Sets the alignment foritem toalignment.
See alsoalignment().
Sets the alignment forcolumn toalignment.
See alsocolumnAlignment().
Sets the fixed width ofcolumn towidth.
Sets the maximum width ofcolumn towidth.
See alsocolumnMaximumWidth().
Sets the minimum width forcolumn towidth.
See alsocolumnMinimumWidth().
Sets the preferred width forcolumn towidth.
See alsocolumnPreferredWidth().
Sets the spacing forcolumn tospacing.
See alsocolumnSpacing().
Sets the stretch factor forcolumn tostretch.
See alsocolumnStretchFactor().
[virtual]void QGraphicsGridLayout::setGeometry(constQRectF & rect)Reimplemented fromQGraphicsLayoutItem::setGeometry().
Sets the bounding geometry of the grid layout torect.
Sets the default horizontal spacing for the grid layout tospacing.
See alsohorizontalSpacing().
Sets the alignment ofrow toalignment.
See alsorowAlignment().
Sets the fixed height for row,row, toheight.
Sets the maximum height for row,row, toheight.
See alsorowMaximumHeight().
Sets the minimum height for row,row, toheight.
See alsorowMinimumHeight().
Sets the preferred height for row,row, toheight.
See alsorowPreferredHeight().
Sets the spacing forrow tospacing.
See alsorowSpacing().
Sets the stretch factor forrow tostretch.
See alsorowStretchFactor().
Sets the grid layout's default spacing, both vertical and horizontal, tospacing.
See alsorowSpacing() andcolumnSpacing().
Sets the default vertical spacing for the grid layout tospacing.
See alsoverticalSpacing().
[virtual]QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, constQSizeF & constraint = QSizeF()) constReimplemented fromQGraphicsLayoutItem::sizeHint().
Returns the default vertical spacing for the grid layout.
See alsosetVerticalSpacing().
© 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.