QTableView Class | Qt Widgets (original) (raw)

The QTableView class provides a default model/view implementation of a table view. More...

Member Function Documentation

[explicit] QTableView::QTableView(QWidget *parent = nullptr)

Constructs a table view with a parent to represent the data.

See also QAbstractItemModel.

[virtual noexcept] QTableView::~QTableView()

Destroys the table view.

void QTableView::clearSpans()

Removes all row and column spans in the table view.

See also setSpan().

int QTableView::columnAt(int x) const

Returns the column in which the given x-coordinate, x, in contents coordinates is located.

Note: This function returns -1 if the given coordinate is not valid (has no column).

See also rowAt().

[protected slot] void QTableView::columnCountChanged(int oldCount, int newCount)

This slot is called whenever columns are added or deleted. The previous number of columns is specified by oldCount, and the new number of columns is specified by newCount.

[protected slot] void QTableView::columnMoved(int column, int oldIndex, int newIndex)

This slot is called to change the index of the given column in the table view. The old index is specified by oldIndex, and the new index by newIndex.

See also rowMoved().

[protected slot] void QTableView::columnResized(int column, int oldWidth, int newWidth)

This slot is called to change the width of the given column. The old width is specified by oldWidth, and the new width by newWidth.

See also rowResized().

int QTableView::columnSpan(int row, int column) const

Returns the column span of the table element at (row, column). The default is 1.

See also setSpan() and rowSpan().

int QTableView::columnViewportPosition(int column) const

Returns the x-coordinate in contents coordinates of the given column.

int QTableView::columnWidth(int column) const

Returns the width of the given column.

See also setColumnWidth(), resizeColumnToContents(), and rowHeight().

[override virtual protected] void QTableView::currentChanged(const QModelIndex &current, const QModelIndex &previous)

Reimplements: QAbstractItemView::currentChanged(const QModelIndex &current, const QModelIndex &previous).

[override virtual protected] void QTableView::dropEvent(QDropEvent *event)

Reimplements: QAbstractItemView::dropEvent(QDropEvent *event).

[slot] void QTableView::hideColumn(int column)

Hide the given column.

See also showColumn() and hideRow().

[slot] void QTableView::hideRow(int row)

Hide the given row.

See also showRow() and hideColumn().

QHeaderView *QTableView::horizontalHeader() const

Returns the table view's horizontal header.

See also setHorizontalHeader(), verticalHeader(), and QAbstractItemModel::headerData().

[override virtual protected] int QTableView::horizontalOffset() const

Reimplements: QAbstractItemView::horizontalOffset() const.

Returns the horizontal offset of the items in the table view.

Note that the table view uses the horizontal header section positions to determine the positions of columns in the view.

See also verticalOffset().

[override virtual] QModelIndex QTableView::indexAt(const QPoint &pos) const

Reimplements: QAbstractItemView::indexAt(const QPoint &point) const.

Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.

[override virtual protected] void QTableView::initViewItemOption(QStyleOptionViewItem *option) const

Reimplements: QAbstractItemView::initViewItemOption(QStyleOptionViewItem *option) const.

bool QTableView::isColumnHidden(int column) const

Returns true if the given column is hidden; otherwise returns false.

See also isRowHidden().

[override virtual protected] bool QTableView::isIndexHidden(const QModelIndex &index) const

Reimplements: QAbstractItemView::isIndexHidden(const QModelIndex &index) const.

bool QTableView::isRowHidden(int row) const

Returns true if the given row is hidden; otherwise returns false.

See also isColumnHidden().

[override virtual protected] QModelIndex QTableView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)

Reimplements: QAbstractItemView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers).

Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers.

See also QAbstractItemView::CursorAction.

[override virtual protected] void QTableView::paintEvent(QPaintEvent *event)

Reimplements: QAbstractScrollArea::paintEvent(QPaintEvent *event).

Paints the table on receipt of the given paint event event.

[slot] void QTableView::resizeColumnToContents(int column)

Resizes the given column based on the size hints of the delegate used to render each item in the column.

Note: Only visible columns will be resized. Reimplement sizeHintForColumn() to resize hidden columns as well.

See also resizeColumnsToContents(), sizeHintForColumn(), and QHeaderView::resizeContentsPrecision().

[slot] void QTableView::resizeColumnsToContents()

Resizes all columns based on the size hints of the delegate used to render each item in the columns.

See also resizeColumnToContents(), sizeHintForColumn(), and QHeaderView::resizeContentsPrecision().

[slot] void QTableView::resizeRowToContents(int row)

Resizes the given row based on the size hints of the delegate used to render each item in the row.

See also resizeRowsToContents(), sizeHintForRow(), and QHeaderView::resizeContentsPrecision().

[slot] void QTableView::resizeRowsToContents()

Resizes all rows based on the size hints of the delegate used to render each item in the rows.

See also resizeRowToContents(), sizeHintForRow(), and QHeaderView::resizeContentsPrecision().

int QTableView::rowAt(int y) const

Returns the row in which the given y-coordinate, y, in contents coordinates is located.

Note: This function returns -1 if the given coordinate is not valid (has no row).

See also columnAt().

[protected slot] void QTableView::rowCountChanged(int oldCount, int newCount)

This slot is called whenever rows are added or deleted. The previous number of rows is specified by oldCount, and the new number of rows is specified by newCount.

int QTableView::rowHeight(int row) const

Returns the height of the given row.

See also setRowHeight(), resizeRowToContents(), and columnWidth().

[protected slot] void QTableView::rowMoved(int row, int oldIndex, int newIndex)

This slot is called to change the index of the given row in the table view. The old index is specified by oldIndex, and the new index by newIndex.

See also columnMoved().

[protected slot] void QTableView::rowResized(int row, int oldHeight, int newHeight)

This slot is called to change the height of the given row. The old height is specified by oldHeight, and the new height by newHeight.

See also columnResized().

int QTableView::rowSpan(int row, int column) const

Returns the row span of the table element at (row, column). The default is 1.

See also setSpan() and columnSpan().

int QTableView::rowViewportPosition(int row) const

Returns the y-coordinate in contents coordinates of the given row.

[override virtual protected] void QTableView::scrollContentsBy(int dx, int dy)

Reimplements: QAbstractScrollArea::scrollContentsBy(int dx, int dy).

Scroll the contents of the table view by (dx, dy).

[override virtual] void QTableView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint = EnsureVisible)

Reimplements: QAbstractItemView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint).

Makes sure that the given index is visible in the table view, scrolling if necessary.

[slot] void QTableView::selectColumn(int column)

Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.

See also selectRow().

[slot] void QTableView::selectRow(int row)

Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.

See also selectColumn().

[override virtual protected] QModelIndexList QTableView::selectedIndexes() const

Reimplements: QAbstractItemView::selectedIndexes() const.

[override virtual protected] void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)

Reimplements: QAbstractItemView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected).

void QTableView::setColumnHidden(int column, bool hide)

If hide is true the given column will be hidden; otherwise it will be shown.

See also isColumnHidden() and setRowHidden().

void QTableView::setColumnWidth(int column, int width)

Sets the width of the given column to be width.

See also columnWidth().

void QTableView::setHorizontalHeader(QHeaderView *header)

Sets the widget to use for the horizontal header to header.

See also horizontalHeader() and setVerticalHeader().

[override virtual] void QTableView::setModel(QAbstractItemModel *model)

Reimplements: QAbstractItemView::setModel(QAbstractItemModel *model).

[override virtual] void QTableView::setRootIndex(const QModelIndex &index)

Reimplements: QAbstractItemView::setRootIndex(const QModelIndex &index).

void QTableView::setRowHeight(int row, int height)

Sets the height of the given row to be height.

See also rowHeight().

void QTableView::setRowHidden(int row, bool hide)

If hide is true row will be hidden, otherwise it will be shown.

See also isRowHidden() and setColumnHidden().

[override virtual protected] void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags)

Reimplements: QAbstractItemView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags).

Selects the items within the given rect and in accordance with the specified selection flags.

[override virtual] void QTableView::setSelectionModel(QItemSelectionModel *selectionModel)

Reimplements: QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel).

void QTableView::setSortingEnabled(bool enable)

If enable is true, enables sorting for the table and immediately trigger a call to sortByColumn() with the current sort section and order

See also isSortingEnabled().

void QTableView::setSpan(int row, int column, int rowSpanCount, int columnSpanCount)

Sets the span of the table element at (row, column) to the number of rows and columns specified by (rowSpanCount, columnSpanCount).

See also rowSpan() and columnSpan().

void QTableView::setVerticalHeader(QHeaderView *header)

Sets the widget to use for the vertical header to header.

See also verticalHeader() and setHorizontalHeader().

[slot] void QTableView::showColumn(int column)

Show the given column.

See also hideColumn() and showRow().

[slot] void QTableView::showRow(int row)

Show the given row.

See also hideRow() and showColumn().

[override virtual protected] int QTableView::sizeHintForColumn(int column) const

Reimplements: QAbstractItemView::sizeHintForColumn(int column) const.

Returns the size hint for the given column's width or -1 if there is no model.

If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the table's horizontal header.

If you reimplement this function in a subclass, note that the value you return will be used when resizeColumnToContents() or QHeaderView::resizeSections() is called. If a larger column width is required by either the horizontal header or the item delegate, the larger width will be used instead.

See also QWidget::sizeHint, horizontalHeader(), and QHeaderView::resizeContentsPrecision().

[override virtual protected] int QTableView::sizeHintForRow(int row) const

Reimplements: QAbstractItemView::sizeHintForRow(int row) const.

Returns the size hint for the given row's height or -1 if there is no model.

If you need to set the height of a given row to a fixed value, call QHeaderView::resizeSection() on the table's vertical header.

If you reimplement this function in a subclass, note that the value you return is only used when resizeRowToContents() is called. In that case, if a larger row height is required by either the vertical header or the item delegate, that width will be used instead.

See also QWidget::sizeHint, verticalHeader(), and QHeaderView::resizeContentsPrecision().

[slot] void QTableView::sortByColumn(int column, Qt::SortOrder order)

Sorts the model by the values in the given column and order.

column may be -1, in which case no sort indicator will be shown and the model will return to its natural, unsorted order. Note that not all models support this and may even crash in this case.

See also sortingEnabled.

[override virtual protected] void QTableView::timerEvent(QTimerEvent *event)

Reimplements: QAbstractItemView::timerEvent(QTimerEvent *event).

[override virtual protected] void QTableView::updateGeometries()

Reimplements: QAbstractItemView::updateGeometries().

QHeaderView *QTableView::verticalHeader() const

Returns the table view's vertical header.

See also setVerticalHeader(), horizontalHeader(), and QAbstractItemModel::headerData().

[override virtual protected] int QTableView::verticalOffset() const

Reimplements: QAbstractItemView::verticalOffset() const.

Returns the vertical offset of the items in the table view.

Note that the table view uses the vertical header section positions to determine the positions of rows in the view.

See also horizontalOffset().

[override virtual protected] QSize QTableView::viewportSizeHint() const

Reimplements: QAbstractItemView::viewportSizeHint() const.

[override virtual] QRect QTableView::visualRect(const QModelIndex &index) const

Reimplements: QAbstractItemView::visualRect(const QModelIndex &index) const.

Returns the rectangle on the viewport occupied by the given index. If the index is hidden in the view it will return a null QRect.

[override virtual protected] QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) const

Reimplements: QAbstractItemView::visualRegionForSelection(const QItemSelection &selection) const.

Returns the rectangle from the viewport of the items in the given selection.

Since 4.7, the returned region only contains rectangles intersecting (or included in) the viewport.