📄 qgridlayout.cpp
字号:
QLayoutItem *QGridLayout::takeAt(int index){ Q_D(QGridLayout); return d->takeAt(index);}/*! Returns the position information of the item with the given \a index. The variables passed as \a row and \a column are updated with the position of the item in the layout, and the \a rowSpan and \a columnSpan variables are updated with the vertical and horizontal spans of the item.*/void QGridLayout::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan){ Q_D(QGridLayout); d->getItemPosition(index, row, column, rowSpan, columnSpan);}/*! \reimp*/void QGridLayout::setGeometry(const QRect &rect){ Q_D(QGridLayout); if (d->isDirty() || rect != geometry()) { QRect cr = alignment() ? alignmentRect(rect) : rect; d->distribute(cr, horizontalSpacing(), verticalSpacing()); QLayout::setGeometry(rect); }}/*! Returns the geometry of the cell with row \a row and column \a column in the grid. Returns an invalid rectangle if \a row or \a 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.*/QRect QGridLayout::cellRect(int row, int column) const{ Q_D(const QGridLayout); return d->cellRect(row, column);}#ifdef QT3_SUPPORT/*! \obsolete Expands this grid so that it will have \a nRows rows and \a nCols columns. Will not shrink the grid. You should not need to call this function because QGridLayout expands automatically as new items are inserted.*/void QGridLayout::expand(int nRows, int nCols){ Q_D(QGridLayout); d->expand(nRows, nCols);}#endif/*! \reimp*/void QGridLayout::addItem(QLayoutItem *item){ Q_D(QGridLayout); int r, c; d->getNextPos(r, c); addItem(item, r, c);}/*! Adds \a item at position \a row, \a column, spanning \a rowSpan rows and \a columnSpan columns, and aligns it according to \a alignment. If \a rowSpan and/or \a columnSpan is -1, then the item will extend to the bottom and/or right edge, respectively. The layout takes ownership of the \a item. \warning Do not use this function to add child layouts or child widget items. Use addLayout() or addWidget() instead.*/void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment){ Q_D(QGridLayout); QGridBox *b = new QGridBox(item); b->setAlignment(alignment); d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1); invalidate();}/* Returns true if the widget \a w can be added to the layout \a l; otherwise returns false.*/static bool checkWidget(QLayout *l, QWidget *w){ if (!w) { qWarning("QLayout: Cannot add null widget to %s/%s", l->metaObject()->className(), l->objectName().toLocal8Bit().data()); return false; } return true;}/*! Adds the given \a widget to the cell grid at \a row, \a column. The top-left position is (0, 0) by default. The alignment is specified by \a alignment. The default alignment is 0, which means that the widget fills the entire cell.*/void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment){ if (!checkWidget(this, widget)) return; if (row < 0 || column < 0) { qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d", widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(), metaObject()->className(), objectName().toLocal8Bit().data(), row, column); return; } addChildWidget(widget); QWidgetItem *b = new QWidgetItem(widget); addItem(b, row, column, 1, 1, alignment);}/*! \overload This version adds the given \a widget to the cell grid, spanning multiple rows/columns. The cell will start at \a fromRow, \a fromColumn spanning \a rowSpan rows and \a columnSpan columns. The \a widget will have the given \a alignment. If \a rowSpan and/or \a columnSpan is -1, then the widget will extend to the bottom and/or right edge, respectively.*/void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment){ Q_D(QGridLayout); if (!checkWidget(this, widget)) return; int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1; int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1; addChildWidget(widget); QGridBox *b = new QGridBox(widget); b->setAlignment(alignment); d->add(b, fromRow, toRow, fromColumn, toColumn); invalidate();}/*! \fn void QGridLayout::addWidget(QWidget *widget) \overload \internal*//*! Places the \a layout at position (\a row, \a column) in the grid. The top-left position is (0, 0). The alignment is specified by \a 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(). \a layout becomes a child of the grid layout.*/void QGridLayout::addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment){ Q_D(QGridLayout); addChildLayout(layout); QGridBox *b = new QGridBox(layout); b->setAlignment(alignment); d->add(b, row, column);}/*! \overload This version adds the layout \a layout to the cell grid, spanning multiple rows/columns. The cell will start at \a row, \a column spanning \a rowSpan rows and \a columnSpan columns. If \a rowSpan and/or \a columnSpan is -1, then the layout will extend to the bottom and/or right edge, respectively.*/void QGridLayout::addLayout(QLayout *layout, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment){ Q_D(QGridLayout); addChildLayout(layout); QGridBox *b = new QGridBox(layout); b->setAlignment(alignment); d->add(b, row, (rowSpan < 0) ? -1 : row + rowSpan - 1, column, (columnSpan < 0) ? -1 : column + columnSpan - 1);}/*! Sets the stretch factor of row \a row to \a 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. \sa rowStretch(), setRowMinimumHeight(), setColumnStretch()*/void QGridLayout::setRowStretch(int row, int stretch){ Q_D(QGridLayout); d->setRowStretch(row, stretch); invalidate();}/*! Returns the stretch factor for row \a row. \sa setRowStretch()*/int QGridLayout::rowStretch(int row) const{ Q_D(const QGridLayout); return d->rowStretch(row);}/*! Returns the stretch factor for column \a column. \sa setColumnStretch()*/int QGridLayout::columnStretch(int column) const{ Q_D(const QGridLayout); return d->colStretch(column);}/*! Sets the stretch factor of column \a column to \a 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. \sa columnStretch(), setRowStretch()*/void QGridLayout::setColumnStretch(int column, int stretch){ Q_D(QGridLayout); d->setColStretch(column, stretch); invalidate();}/*! Sets the minimum height of row \a row to \a minSize pixels. \sa rowMinimumHeight(), setColumnMinimumWidth()*/void QGridLayout::setRowMinimumHeight(int row, int minSize){ Q_D(QGridLayout); d->setRowMinimumHeight(row, minSize); invalidate();}/*! Returns the minimum width set for row \a row. \sa setRowMinimumHeight()*/int QGridLayout::rowMinimumHeight(int row) const{ Q_D(const QGridLayout); return d->rowSpacing(row);}/*! Sets the minimum width of column \a column to \a minSize pixels. \sa columnMinimumWidth(), setRowMinimumHeight()*/void QGridLayout::setColumnMinimumWidth(int column, int minSize){ Q_D(QGridLayout); d->setColumnMinimumWidth(column, minSize); invalidate();}/*! Returns the column spacing for column \a column. \sa setColumnMinimumWidth()*/int QGridLayout::columnMinimumWidth(int column) const{ Q_D(const QGridLayout); return d->colSpacing(column);}/*! \reimp*/Qt::Orientations QGridLayout::expandingDirections() const{ Q_D(const QGridLayout); return d->expandingDirections(horizontalSpacing(), verticalSpacing());}/*! Sets the grid's origin corner, i.e. position (0, 0), to \a corner.*/void QGridLayout::setOriginCorner(Qt::Corner corner){ Q_D(QGridLayout); d->setReversed(corner == Qt::BottomLeftCorner || corner == Qt::BottomRightCorner, corner == Qt::TopRightCorner || corner == Qt::BottomRightCorner);}/*! Returns the corner that's used for the grid's origin, i.e. for position (0, 0).*/Qt::Corner QGridLayout::originCorner() const{ Q_D(const QGridLayout); if (d->horReversed()) { return d->verReversed() ? Qt::BottomRightCorner : Qt::TopRightCorner; } else { return d->verReversed() ? Qt::BottomLeftCorner : Qt::TopLeftCorner; }}/*! \reimp*/void QGridLayout::invalidate(){ Q_D(QGridLayout); d->setDirty(); QLayout::invalidate();}/*! \fn void QGridLayout::addRowSpacing(int row, int minsize) Use addItem(new QSpacerItem(0, minsize), row, 0) instead.*//*! \fn void QGridLayout::addColSpacing(int col, int minsize) Use addItem(new QSpacerItem(minsize, 0), 0, col) instead.*//*! \fn void QGridLayout::addMultiCellWidget(QWidget *widget, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment align = 0) Use an addWidget() overload that allows you to specify row and column spans instead.*//*! \fn void QGridLayout::addMultiCell(QLayoutItem *l, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment align = 0) Use an addItem() overload that allows you to specify row and column spans instead.*//*! \fn void QGridLayout::addMultiCellLayout(QLayout *layout, int fromRow, int toRow, int fromCol, int toCol, Qt::Alignment align = 0) Use an addLayout() overload that allows you to specify row and column spans instead.*//*! \fn int QGridLayout::numRows() const Use rowCount() instead.*//*! \fn int QGridLayout::numCols() const Use columnCount() instead.*//*! \fn void QGridLayout::setColStretch(int col, int stretch) Use setColumnStretch() instead.*//*! \fn int QGridLayout::colStretch(int col) const Use columnStretch() instead.*//*! \fn void QGridLayout::setColSpacing(int col, int minSize) Use setColumnMinimumWidth() instead.*//*! \fn int QGridLayout::colSpacing(int col) const Use columnSpacing() instead.*//*! \fn void QGridLayout::setRowSpacing(int row, int minSize) Use setRowMinimumHeight(\a row, \a minSize) instead.*//*! \fn int QGridLayout::rowSpacing(int row) const Use rowMinimumHeight(\a row) instead.*//*! \fn QRect QGridLayout::cellGeometry(int row, int column) const Use cellRect(\a row, \a column) instead.*//*! \fn void QGridLayout::setOrigin(Qt::Corner corner) Use setOriginCorner(\a corner) instead.*//*! \fn Qt::Corner QGridLayout::origin() const Use originCorner() instead.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -