The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View. 更多...
| 頭: | #include <QGraphicsGridLayout> |
| qmake: | QT += widgets |
| Since: | Qt 4.4 |
| 繼承: | QGraphicsLayout |
| QGraphicsGridLayout (QGraphicsLayoutItem * parent = Q_NULLPTR) | |
| virtual | ~QGraphicsGridLayout () |
| void | addItem (QGraphicsLayoutItem * item , int row , int column , int rowSpan , int columnSpan , Qt::Alignment alignment = Qt::Alignment()) |
| void | addItem (QGraphicsLayoutItem * item , int row , int column , Qt::Alignment alignment = Qt::Alignment()) |
| 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 |
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.
最常見方式是使用 QGraphicsGridLayout is to construct an object on the heap with no parent, add widgets and layouts by calling addItem (), and finally assign the layout to a widget by calling QGraphicsWidget::setLayout (). QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.
QGraphicsScene scene; QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit); QGraphicsWidget *pushButton = scene.addWidget(new QPushButton); QGraphicsGridLayout *layout = new QGraphicsGridLayout; layout->addItem(textEdit, 0, 0); layout->addItem(pushButton, 0, 1); QGraphicsWidget *form = new QGraphicsWidget; form->setLayout(layout); scene.addItem(form);
The layout takes ownership of the items. In some cases when the layout item also inherits from QGraphicsItem (譬如 QGraphicsWidget ) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem::setOwnedByLayout () how to handle this. You can access each item in the layout by calling count () 和 itemAt ()。調用 removeAt () 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 calling setAlignment (), and check the alignment for any item by calling alignment (). You can also set the alignment for an entire row or column by calling setRowAlignment () 和 setColumnAlignment () respectively. By default, items are aligned to the top left.
另請參閱 QGraphicsLinearLayout and QGraphicsWidget .
構造 QGraphicsGridLayout 實例。 parent 被傳遞給 QGraphicsLayout 的構造函數。
[虛擬]
QGraphicsGridLayout::
~QGraphicsGridLayout
()
銷毀 QGraphicsGridLayout 對象。
添加 item to the grid on row and column . You can specify a rowSpan and columnSpan and an optional alignment .
添加 item to the grid on row and column . You can specify an optional alignment for item .
返迴對齊方式為 item .
另請參閱 setAlignment ().
返迴對齊方式為 column .
另請參閱 setColumnAlignment ().
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).
返迴最大寬度為 column .
另請參閱 setColumnMaximumWidth ().
Returns the minimum width for column .
另請參閱 setColumnMinimumWidth ().
Returns the preferred width for column .
另請參閱 setColumnPreferredWidth ().
Returns the column spacing for column .
另請參閱 setColumnSpacing ().
Returns the stretch factor for column .
另請參閱 setColumnStretchFactor ().
[虛擬]
int
QGraphicsGridLayout::
count
() const
重實現自 QGraphicsLayout::count ().
Returns the number of layout items in this grid layout.
Returns the default horizontal spacing for the grid layout.
另請參閱 setHorizontalSpacing ().
[虛擬]
void
QGraphicsGridLayout::
invalidate
()
重實現自 QGraphicsLayout::invalidate ().
Returns a pointer to the layout item at ( row , column ).
[虛擬]
QGraphicsLayoutItem
*QGraphicsGridLayout::
itemAt
(
int
index
) const
重實現自 QGraphicsLayout::itemAt ().
Returns the layout item at index , or 0 if there is no layout item at this index.
[虛擬]
void
QGraphicsGridLayout::
removeAt
(
int
index
)
重實現自 QGraphicsLayout::removeAt ().
移除布局項在 index without destroying it. Ownership of the item is transferred to the caller.
另請參閱 addItem ().
移除布局項 item without destroying it. Ownership of the item is transferred to the caller.
另請參閱 addItem ().
Returns the alignment of row .
另請參閱 setRowAlignment ().
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 .
另請參閱 setRowMaximumHeight ().
Returns the minimum height for row, row .
另請參閱 setRowMinimumHeight ().
Returns the preferred height for row, row .
另請參閱 setRowPreferredHeight ().
Returns the row spacing for row .
另請參閱 setRowSpacing ().
Returns the stretch factor for row .
另請參閱 setRowStretchFactor ().
Sets the alignment for item to alignment .
另請參閱 alignment ().
Sets the alignment for column to alignment .
另請參閱 columnAlignment ().
Sets the fixed width of column to width .
Sets the maximum width of column to width .
另請參閱 columnMaximumWidth ().
Sets the minimum width for column to width .
另請參閱 columnMinimumWidth ().
Sets the preferred width for column to width .
另請參閱 columnPreferredWidth ().
Sets the spacing for column to spacing .
另請參閱 columnSpacing ().
設置拉伸因子為 column to stretch .
另請參閱 columnStretchFactor ().
[虛擬]
void
QGraphicsGridLayout::
setGeometry
(const
QRectF
&
rect
)
重實現自 QGraphicsLayoutItem::setGeometry ().
Sets the bounding geometry of the grid layout to rect .
Sets the default horizontal spacing for the grid layout to spacing .
另請參閱 horizontalSpacing ().
Sets the alignment of row to alignment .
另請參閱 rowAlignment ().
Sets the fixed height for row, row ,到 height .
Sets the maximum height for row, row ,到 height .
另請參閱 rowMaximumHeight ().
Sets the minimum height for row, row ,到 height .
另請參閱 rowMinimumHeight ().
Sets the preferred height for row, row ,到 height .
另請參閱 rowPreferredHeight ().
Sets the spacing for row to spacing .
另請參閱 rowSpacing ().
設置拉伸因子為 row to stretch .
另請參閱 rowStretchFactor ().
Sets the grid layout's default spacing, both vertical and horizontal, to spacing .
另請參閱 rowSpacing () 和 columnSpacing ().
Sets the default vertical spacing for the grid layout to spacing .
另請參閱 verticalSpacing ().
[虛擬]
QSizeF
QGraphicsGridLayout::
sizeHint
(
Qt::SizeHint
which
, const
QSizeF
&
constraint
= QSizeF()) const
重實現自 QGraphicsLayoutItem::sizeHint ().
Returns the default vertical spacing for the grid layout.
另請參閱 setVerticalSpacing ().