Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTableView Class Reference

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

#include <qtableview.h>

+ Inheritance diagram for QTableView:
+ Collaboration diagram for QTableView:

Public Slots

void selectRow (int row)
 Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.
 
void selectColumn (int column)
 Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.
 
void hideRow (int row)
 Hide the given row.
 
void hideColumn (int column)
 Hide the given column.
 
void showRow (int row)
 Show the given row.
 
void showColumn (int column)
 Show the given column.
 
void resizeRowToContents (int row)
 Resizes the given row based on the size hints of the delegate used to render each item in the row.
 
void resizeRowsToContents ()
 Resizes all rows based on the size hints of the delegate used to render each item in the rows.
 
void resizeColumnToContents (int column)
 Resizes the given column based on the size hints of the delegate used to render each item in the column.
 
void resizeColumnsToContents ()
 Resizes all columns based on the size hints of the delegate used to render each item in the columns.
 
void sortByColumn (int column, Qt::SortOrder order)
 
void setShowGrid (bool show)
 
- Public Slots inherited from QAbstractItemView
virtual void reset ()
 Reset the internal state of the view.
 
virtual void selectAll ()
 Selects all items in the view.
 
void edit (const QModelIndex &index)
 Starts editing the item corresponding to the given index if it is editable.
 
void clearSelection ()
 Deselects all selected items.
 
void setCurrentIndex (const QModelIndex &index)
 Sets the current item to be the item at index.
 
void scrollToTop ()
 
void scrollToBottom ()
 
void update (const QModelIndex &index)
 

Public Member Functions

 QTableView (QWidget *parent=nullptr)
 Constructs a table view with a parent to represent the data.
 
 ~QTableView ()
 Destroys the table view.
 
void setModel (QAbstractItemModel *model) override
 \reimp
 
void setRootIndex (const QModelIndex &index) override
 \reimp
 
void setSelectionModel (QItemSelectionModel *selectionModel) override
 \reimp
 
void doItemsLayout () override
 
QHeaderViewhorizontalHeader () const
 Returns the table view's horizontal header.
 
QHeaderViewverticalHeader () const
 Returns the table view's vertical header.
 
void setHorizontalHeader (QHeaderView *header)
 Sets the widget to use for the horizontal header to header.
 
void setVerticalHeader (QHeaderView *header)
 Sets the widget to use for the vertical header to header.
 
int rowViewportPosition (int row) const
 Returns the y-coordinate in contents coordinates of the given row.
 
int rowAt (int y) const
 Returns the row in which the given y-coordinate, y, in contents coordinates is located.
 
void setRowHeight (int row, int height)
 
int rowHeight (int row) const
 Returns the height of the given row.
 
int columnViewportPosition (int column) const
 Returns the x-coordinate in contents coordinates of the given column.
 
int columnAt (int x) const
 Returns the column in which the given x-coordinate, x, in contents coordinates is located.
 
void setColumnWidth (int column, int width)
 
int columnWidth (int column) const
 Returns the width of the given column.
 
bool isRowHidden (int row) const
 Returns true if the given row is hidden; otherwise returns false.
 
void setRowHidden (int row, bool hide)
 If hide is true row will be hidden, otherwise it will be shown.
 
bool isColumnHidden (int column) const
 Returns true if the given column is hidden; otherwise returns false.
 
void setColumnHidden (int column, bool hide)
 If hide is true the given column will be hidden; otherwise it will be shown.
 
void 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.
 
bool isSortingEnabled () const
 
bool showGrid () const
 
Qt::PenStyle gridStyle () const
 
void setGridStyle (Qt::PenStyle style)
 
void setWordWrap (bool on)
 
bool wordWrap () const
 
QRect visualRect (const QModelIndex &index) const override
 \reimp
 
void scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) override
 \reimp
 
QModelIndex indexAt (const QPoint &p) const override
 Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
 
void setSpan (int row, int column, int rowSpan, int columnSpan)
 
int rowSpan (int row, int column) const
 
int columnSpan (int row, int column) const
 
void clearSpans ()
 
- Public Member Functions inherited from QAbstractItemView
 QAbstractItemView (QWidget *parent=nullptr)
 Constructs an abstract item view with the given parent.
 
 ~QAbstractItemView ()
 Destroys the view.
 
QAbstractItemModelmodel () const
 Returns the model that this view is presenting.
 
QItemSelectionModelselectionModel () const
 Returns the current selection model.
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 Sets the item delegate for this view and its model to delegate.
 
QAbstractItemDelegateitemDelegate () const
 Returns the item delegate used by this view and model.
 
void setSelectionMode (QAbstractItemView::SelectionMode mode)
 
QAbstractItemView::SelectionMode selectionMode () const
 
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior)
 
QAbstractItemView::SelectionBehavior selectionBehavior () const
 
QModelIndex currentIndex () const
 Returns the model index of the current item.
 
QModelIndex rootIndex () const
 Returns the model index of the model's root item.
 
void setEditTriggers (EditTriggers triggers)
 
EditTriggers editTriggers () const
 
void setVerticalScrollMode (ScrollMode mode)
 
ScrollMode verticalScrollMode () const
 
void resetVerticalScrollMode ()
 
void setHorizontalScrollMode (ScrollMode mode)
 
ScrollMode horizontalScrollMode () const
 
void resetHorizontalScrollMode ()
 
void setAutoScroll (bool enable)
 
bool hasAutoScroll () const
 
void setAutoScrollMargin (int margin)
 
int autoScrollMargin () const
 
void setTabKeyNavigation (bool enable)
 
bool tabKeyNavigation () const
 
void setAlternatingRowColors (bool enable)
 
bool alternatingRowColors () const
 
void setIconSize (const QSize &size)
 
QSize iconSize () const
 
void setTextElideMode (Qt::TextElideMode mode)
 
Qt::TextElideMode textElideMode () const
 
virtual void keyboardSearch (const QString &search)
 Moves to and selects the item best matching the string search.
 
QSize sizeHintForIndex (const QModelIndex &index) const
 Returns the size hint for the item with the specified index or an invalid size for invalid indexes.
 
void openPersistentEditor (const QModelIndex &index)
 Opens a persistent editor on the item at the given index.
 
void closePersistentEditor (const QModelIndex &index)
 Closes the persistent editor for the item at the given index.
 
bool isPersistentEditorOpen (const QModelIndex &index) const
 
void setIndexWidget (const QModelIndex &index, QWidget *widget)
 
QWidgetindexWidget (const QModelIndex &index) const
 
void setItemDelegateForRow (int row, QAbstractItemDelegate *delegate)
 
QAbstractItemDelegateitemDelegateForRow (int row) const
 
void setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate)
 
QAbstractItemDelegateitemDelegateForColumn (int column) const
 
virtual QAbstractItemDelegateitemDelegateForIndex (const QModelIndex &index) const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 \reimp
 

Protected Slots

void rowMoved (int row, int oldIndex, int newIndex)
 This slot is called to change the index of the given row in the table view.
 
void columnMoved (int column, int oldIndex, int newIndex)
 This slot is called to change the index of the given column in the table view.
 
void rowResized (int row, int oldHeight, int newHeight)
 This slot is called to change the height of the given row.
 
void columnResized (int column, int oldWidth, int newWidth)
 This slot is called to change the width of the given column.
 
void rowCountChanged (int oldCount, int newCount)
 This slot is called whenever rows are added or deleted.
 
void columnCountChanged (int oldCount, int newCount)
 This slot is called whenever columns are added or deleted.
 
- Protected Slots inherited from QAbstractItemView
virtual void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
 This slot is called when items with the given roles are changed in the model.
 
virtual void rowsInserted (const QModelIndex &parent, int start, int end)
 This slot is called when rows are inserted.
 
virtual void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
 This slot is called when rows are about to be removed.
 
virtual void updateEditorData ()
 
virtual void updateEditorGeometries ()
 
virtual void verticalScrollbarValueChanged (int value)
 
virtual void horizontalScrollbarValueChanged (int value)
 
virtual void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
 Closes the given editor, and releases it.
 
virtual void commitData (QWidget *editor)
 Commit the data in the editor to the model.
 
virtual void editorDestroyed (QObject *editor)
 This function is called when the given editor has been destroyed.
 

Protected Member Functions

 QTableView (QTableViewPrivate &, QWidget *parent)
 
void scrollContentsBy (int dx, int dy) override
 \reimp
 
void initViewItemOption (QStyleOptionViewItem *option) const override
 \reimp
 
void paintEvent (QPaintEvent *e) override
 Paints the table on receipt of the given paint event event.
 
void timerEvent (QTimerEvent *event) override
 \reimp
 
int horizontalOffset () const override
 Returns the horizontal offset of the items in the table view.
 
int verticalOffset () const override
 Returns the vertical offset of the items in the table view.
 
QModelIndex moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
 Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers.
 
void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command) override
 Selects the items within the given rect and in accordance with the specified selection flags.
 
QRegion visualRegionForSelection (const QItemSelection &selection) const override
 \reimp
 
QModelIndexList selectedIndexes () const override
 \reimp
 
void updateGeometries () override
 \reimp
 
QSize viewportSizeHint () const override
 \reimp
 
int sizeHintForRow (int row) const override
 Returns the size hint for the given row's height or -1 if there is no model.
 
int sizeHintForColumn (int column) const override
 Returns the size hint for the given column's width or -1 if there is no model.
 
void verticalScrollbarAction (int action) override
 
void horizontalScrollbarAction (int action) override
 
bool isIndexHidden (const QModelIndex &index) const override
 \reimp
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) override
 \reimp
 
void currentChanged (const QModelIndex &current, const QModelIndex &previous) override
 \reimp
 
- Protected Member Functions inherited from QAbstractItemView
 QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=nullptr)
 
virtual bool edit (const QModelIndex &index, EditTrigger trigger, QEvent *event)
 Starts editing the item at index, creating an editor if necessary, and returns true if the view's \l{State} is now EditingState; otherwise returns false.
 
virtual QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex &index, const QEvent *event=nullptr) const
 Returns the SelectionFlags to be used when updating a selection model for the specified index.
 
State state () const
 Returns the item view's state.
 
void setState (State state)
 Sets the item view's state to the given state.
 
void scheduleDelayedItemsLayout ()
 Schedules a layout of the items in the view to be executed when the event processing starts.
 
void executeDelayedItemsLayout ()
 Executes the scheduled layouts without waiting for the event processing to begin.
 
void setDirtyRegion (const QRegion &region)
 
void scrollDirtyRegion (int dx, int dy)
 Prepares the view for scrolling by ({dx},{dy}) pixels by moving the dirty regions in the opposite direction.
 
QPoint dirtyRegionOffset () const
 Returns the offset of the dirty regions in the view.
 
void startAutoScroll ()
 
void stopAutoScroll ()
 
void doAutoScroll ()
 
bool focusNextPrevChild (bool next) override
 \reimp
 
bool event (QEvent *event) override
 \reimp
 
bool viewportEvent (QEvent *event) override
 This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::ToolTip,or a QEvent::WhatsThis.
 
void mousePressEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is pressed while the cursor is inside the widget.
 
void mouseMoveEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse move event is sent to the widget.
 
void mouseReleaseEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is released, after a mouse press event on the widget.
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 This function is called with the given event when a mouse button is double clicked inside the widget.
 
void focusInEvent (QFocusEvent *event) override
 This function is called with the given event when the widget obtains the focus.
 
void focusOutEvent (QFocusEvent *event) override
 This function is called with the given event when the widget loses the focus.
 
void keyPressEvent (QKeyEvent *event) override
 This function is called with the given event when a key event is sent to the widget.
 
void resizeEvent (QResizeEvent *event) override
 This function is called with the given event when a resize event is sent to the widget.
 
void timerEvent (QTimerEvent *event) override
 This function is called with the given event when a timer event is sent to the widget.
 
void inputMethodEvent (QInputMethodEvent *event) override
 \reimp
 
bool eventFilter (QObject *object, QEvent *event) override
 \reimp
 
QSize viewportSizeHint () const override
 

Properties

bool showGrid
 whether the grid is shown
 
Qt::PenStyle gridStyle
 the pen style used to draw the grid.
 
bool sortingEnabled
 whether sorting is enabled
 
bool wordWrap
 the item text word-wrapping policy
 
- Properties inherited from QAbstractItemView
bool autoScroll
 whether autoscrolling in drag move events is enabled
 
int autoScrollMargin
 the size of the area when auto scrolling is triggered
 
EditTriggers editTriggers
 which actions will initiate item editing
 
bool tabKeyNavigation
 whether item navigation with tab and backtab is enabled.
 
bool alternatingRowColors
 whether to draw the background using alternating colors
 
SelectionMode selectionMode
 which selection mode the view operates in
 
SelectionBehavior selectionBehavior
 which selection behavior the view uses
 
QSize iconSize
 the size of items' icons
 
Qt::TextElideMode textElideMode
 the position of the "..." in elided text.
 
ScrollMode verticalScrollMode
 how the view scrolls its contents in the vertical direction
 
ScrollMode horizontalScrollMode
 how the view scrolls its contents in the horizontal direction
 

Friends

class QAccessibleItemView
 

Additional Inherited Members

- Public Types inherited from QAbstractItemView
enum  SelectionMode {
  NoSelection , SingleSelection , MultiSelection , ExtendedSelection ,
  ContiguousSelection
}
 This enum indicates how the view responds to user selections: More...
 
enum  SelectionBehavior { SelectItems , SelectRows , SelectColumns }
 \value SelectItems Selecting single items. More...
 
enum  ScrollHint { EnsureVisible , PositionAtTop , PositionAtBottom , PositionAtCenter }
 \value EnsureVisible Scroll to ensure that the item is visible. More...
 
enum  EditTrigger {
  NoEditTriggers = 0 , CurrentChanged = 1 , DoubleClicked = 2 , SelectedClicked = 4 ,
  EditKeyPressed = 8 , AnyKeyPressed = 16 , AllEditTriggers = 31
}
 This enum describes actions which will initiate item editing. More...
 
enum  ScrollMode { ScrollPerItem , ScrollPerPixel }
 
- Signals inherited from QAbstractItemView
void pressed (const QModelIndex &index)
 This signal is emitted when a mouse button is pressed.
 
void clicked (const QModelIndex &index)
 This signal is emitted when a mouse button is left-clicked.
 
void doubleClicked (const QModelIndex &index)
 This signal is emitted when a mouse button is double-clicked.
 
void activated (const QModelIndex &index)
 This signal is emitted when the item specified by index is activated by the user.
 
void entered (const QModelIndex &index)
 This signal is emitted when the mouse cursor enters the item specified by index.
 
void viewportEntered ()
 This signal is emitted when the mouse cursor enters the viewport.
 
void iconSizeChanged (const QSize &size)
 
- Protected Types inherited from QAbstractItemView
enum  CursorAction {
  MoveUp , MoveDown , MoveLeft , MoveRight ,
  MoveHome , MoveEnd , MovePageUp , MovePageDown ,
  MoveNext , MovePrevious
}
 This enum describes the different ways to navigate between items,. More...
 
enum  State {
  NoState , DraggingState , DragSelectingState , EditingState ,
  ExpandingState , CollapsingState , AnimatingState
}
 Describes the different states the view can be in. More...
 

Detailed Description

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

\inmodule QtWidgets

A QTableView implements a table view that displays items from a model. This class is used to provide standard tables that were previously provided by the QTable class, but using the more flexible approach provided by Qt's model/view architecture.

The QTableView class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}.

QTableView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.

Definition at line 17 of file qtableview.h.

Constructor & Destructor Documentation

◆ QTableView() [1/2]

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

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

See also
QAbstractItemModel

Definition at line 1219 of file qtableview.cpp.

References d.

◆ ~QTableView()

QTableView::~QTableView ( )

Destroys the table view.

Definition at line 1239 of file qtableview.cpp.

References d.

◆ QTableView() [2/2]

QTableView::QTableView ( QTableViewPrivate & dd,
QWidget * parent )
protected

Definition at line 1229 of file qtableview.cpp.

References d.

Member Function Documentation

◆ clearSpans()

void QTableView::clearSpans ( )
Since
4.4

Removes all row and column spans in the table view.

See also
setSpan()

Definition at line 3401 of file qtableview.cpp.

References d.

◆ columnAt()

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()

Definition at line 2628 of file qtableview.cpp.

References d.

Referenced by indexAt().

+ Here is the caller graph for this function:

◆ columnCountChanged

void QTableView::columnCountChanged ( int oldCount,
int newCount )
protectedslot

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.

Definition at line 2254 of file qtableview.cpp.

References d, QAbstractItemView::horizontalScrollMode, QAbstractItemView::ScrollPerItem, and updateGeometries().

Referenced by setHorizontalHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ columnMoved

void QTableView::columnMoved ( int column,
int oldIndex,
int newIndex )
protectedslot

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()

Definition at line 3146 of file qtableview.cpp.

References columnViewportPosition(), columnWidth(), d, Q_UNUSED, qMax(), qMin(), and updateGeometries().

Referenced by setHorizontalHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ columnResized

void QTableView::columnResized ( int column,
int oldWidth,
int newWidth )
protectedslot

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()

Definition at line 3035 of file qtableview.cpp.

References d.

Referenced by setHorizontalHeader().

+ Here is the caller graph for this function:

◆ columnSpan()

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

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

See also
setSpan(), rowSpan()

Definition at line 3387 of file qtableview.cpp.

References d.

Referenced by setSpan().

+ Here is the caller graph for this function:

◆ columnViewportPosition()

int QTableView::columnViewportPosition ( int column) const

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

Definition at line 2613 of file qtableview.cpp.

References d.

Referenced by columnMoved(), paintEvent(), timerEvent(), visualRect(), and visualRegionForSelection().

+ Here is the caller graph for this function:

◆ columnWidth()

int QTableView::columnWidth ( int column) const

Returns the width of the given column.

See also
resizeColumnToContents(), rowHeight()

Definition at line 2650 of file qtableview.cpp.

References d.

Referenced by columnMoved(), paintEvent(), scrollTo(), timerEvent(), visualRect(), and visualRegionForSelection().

+ Here is the caller graph for this function:

◆ currentChanged()

void QTableView::currentChanged ( const QModelIndex & current,
const QModelIndex & previous )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 3491 of file qtableview.cpp.

References QAbstractItemView::currentChanged(), d, and QModelIndex::isValid().

+ Here is the call graph for this function:

◆ doItemsLayout()

void QTableView::doItemsLayout ( )
overridevirtual

Reimplemented from QAbstractItemView.

Definition at line 1307 of file qtableview.cpp.

References d, and QAbstractItemView::doItemsLayout().

+ Here is the call graph for this function:

◆ gridStyle()

Qt::PenStyle QTableView::gridStyle ( ) const

Definition at line 2787 of file qtableview.cpp.

References d.

◆ hideColumn

void QTableView::hideColumn ( int column)
slot

Hide the given column.

See also
showColumn(), hideRow()

Definition at line 3208 of file qtableview.cpp.

References d.

Referenced by QSqlTableModel_snippets().

+ Here is the caller graph for this function:

◆ hideRow

void QTableView::hideRow ( int row)
slot

Hide the given row.

See also
showRow(), hideColumn()

Definition at line 3197 of file qtableview.cpp.

References d.

◆ horizontalHeader()

QHeaderView * QTableView::horizontalHeader ( ) const

Returns the table view's horizontal header.

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

Definition at line 1344 of file qtableview.cpp.

References d.

Referenced by QtPrivate::QCalendarView::QCalendarView(), paintEvent(), setSelection(), setSortingEnabled(), QTableWidget::sortItems(), timerEvent(), QTableWidget::visualColumn(), and visualRegionForSelection().

+ Here is the caller graph for this function:

◆ horizontalOffset()

int QTableView::horizontalOffset ( ) const
overrideprotectedvirtual

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()

Implements QAbstractItemView.

Definition at line 1720 of file qtableview.cpp.

References d.

Referenced by scrollTo().

+ Here is the caller graph for this function:

◆ horizontalScrollbarAction()

void QTableView::horizontalScrollbarAction ( int action)
overrideprotectedvirtual

Reimplemented from QAbstractItemView.

Definition at line 3326 of file qtableview.cpp.

References QAbstractItemView::horizontalScrollbarAction().

+ Here is the call graph for this function:

◆ indexAt()

QModelIndex QTableView::indexAt ( const QPoint & p) const
overridevirtual

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

Implements QAbstractItemView.

Definition at line 1695 of file qtableview.cpp.

References columnAt(), d, pos, rowAt(), and QSpanCollection::Span::top().

Referenced by QtPrivate::QCalendarView::handleMouseEvent(), QTableWidget::itemAt(), and setSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initViewItemOption()

void QTableView::initViewItemOption ( QStyleOptionViewItem * option) const
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 1489 of file qtableview.cpp.

References QAbstractItemView::initViewItemOption().

Referenced by paintEvent(), sizeHintForColumn(), and sizeHintForRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isColumnHidden()

bool QTableView::isColumnHidden ( int column) const

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

See also
isRowHidden()

Definition at line 2685 of file qtableview.cpp.

References d.

Referenced by isIndexHidden(), moveCursor(), and scrollTo().

+ Here is the caller graph for this function:

◆ isIndexHidden()

bool QTableView::isIndexHidden ( const QModelIndex & index) const
overrideprotectedvirtual

\reimp

Implements QAbstractItemView.

Definition at line 3334 of file qtableview.cpp.

References d, isColumnHidden(), isRowHidden(), and Q_ASSERT.

Referenced by selectedIndexes(), QTableWidget::selectedItems(), and visualRect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRowHidden()

bool QTableView::isRowHidden ( int row) const

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

See also
isColumnHidden()

Definition at line 2661 of file qtableview.cpp.

References d.

Referenced by isIndexHidden(), moveCursor(), and scrollTo().

+ Here is the caller graph for this function:

◆ isSortingEnabled()

bool QTableView::isSortingEnabled ( ) const

Definition at line 2753 of file qtableview.cpp.

References d.

Referenced by QTableWidget::isSortingEnabled().

+ Here is the caller graph for this function:

◆ moveCursor()

QModelIndex QTableView::moveCursor ( CursorAction cursorAction,
Qt::KeyboardModifiers modifiers )
overrideprotectedvirtual

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

See also
QAbstractItemView::CursorAction

Implements QAbstractItemView.

Definition at line 1748 of file qtableview.cpp.

References QModelIndex::column(), Qt::ControlModifier, QAbstractItemView::currentIndex(), d, QTableViewPrivate::Decreasing, QRect::height(), QTableViewPrivate::Increasing, isColumnHidden(), isRowHidden(), QModelIndex::isValid(), QAbstractItemView::model(), QModelIndex::model(), QAbstractItemView::MoveDown, QAbstractItemView::MoveEnd, QAbstractItemView::MoveHome, QAbstractItemView::MoveLeft, QAbstractItemView::MoveNext, QAbstractItemView::MovePageDown, QAbstractItemView::MovePageUp, QAbstractItemView::MovePrevious, QAbstractItemView::MoveRight, QAbstractItemView::MoveUp, Q_ASSERT, Q_UNUSED, QModelIndex::row(), rowAt(), and visualRect().

Referenced by QtPrivate::QCalendarView::moveCursor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ paintEvent()

◆ resizeColumnsToContents

void QTableView::resizeColumnsToContents ( )
slot

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

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

Definition at line 3285 of file qtableview.cpp.

References d, and QHeaderView::ResizeToContents.

◆ resizeColumnToContents

void QTableView::resizeColumnToContents ( int column)
slot

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(), QHeaderView::resizeContentsPrecision()

Definition at line 3271 of file qtableview.cpp.

References d, header(), qMax(), and sizeHintForColumn().

Referenced by setHorizontalHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resizeRowsToContents

void QTableView::resizeRowsToContents ( )
slot

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

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

Definition at line 3256 of file qtableview.cpp.

References d, and QHeaderView::ResizeToContents.

◆ resizeRowToContents

void QTableView::resizeRowToContents ( int row)
slot

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

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

Definition at line 3242 of file qtableview.cpp.

References d, header(), qMax(), and sizeHintForRow().

Referenced by setVerticalHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rowAt()

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()

Definition at line 2581 of file qtableview.cpp.

References d.

Referenced by indexAt(), and moveCursor().

+ Here is the caller graph for this function:

◆ rowCountChanged

void QTableView::rowCountChanged ( int oldCount,
int newCount )
protectedslot

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.

Definition at line 2239 of file qtableview.cpp.

References d.

Referenced by setVerticalHeader().

+ Here is the caller graph for this function:

◆ rowHeight()

int QTableView::rowHeight ( int row) const

Returns the height of the given row.

See also
resizeRowToContents(), columnWidth()

Definition at line 2603 of file qtableview.cpp.

References d.

Referenced by paintEvent(), rowMoved(), visualRect(), and visualRegionForSelection().

+ Here is the caller graph for this function:

◆ rowMoved

void QTableView::rowMoved ( int row,
int oldIndex,
int newIndex )
protectedslot

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()

Definition at line 3117 of file qtableview.cpp.

References d, Q_UNUSED, qMax(), qMin(), rowHeight(), rowViewportPosition(), and updateGeometries().

Referenced by setVerticalHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rowResized

void QTableView::rowResized ( int row,
int oldHeight,
int newHeight )
protectedslot

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()

Definition at line 3020 of file qtableview.cpp.

References d.

Referenced by setVerticalHeader().

+ Here is the caller graph for this function:

◆ rowSpan()

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

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

See also
setSpan(), columnSpan()

Definition at line 3373 of file qtableview.cpp.

References d.

Referenced by setSpan().

+ Here is the caller graph for this function:

◆ rowViewportPosition()

int QTableView::rowViewportPosition ( int row) const

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

Definition at line 2566 of file qtableview.cpp.

References d.

Referenced by paintEvent(), rowMoved(), timerEvent(), visualRect(), and visualRegionForSelection().

+ Here is the caller graph for this function:

◆ scrollContentsBy()

void QTableView::scrollContentsBy ( int dx,
int dy )
overrideprotected

\reimp

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

Definition at line 1448 of file qtableview.cpp.

References d, QAbstractItemView::horizontalScrollMode, QAbstractItemView::ScrollPerItem, and QAbstractItemView::verticalScrollMode.

◆ scrollTo()

void QTableView::scrollTo ( const QModelIndex & index,
ScrollHint hint = EnsureVisible )
overridevirtual

\reimp

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

Implements QAbstractItemView.

Definition at line 2893 of file qtableview.cpp.

References columnWidth(), d, QAbstractItemView::EnsureVisible, hint(), horizontalOffset(), QAbstractItemView::horizontalScrollMode, isColumnHidden(), isRowHidden(), QAbstractItemView::PositionAtBottom, QAbstractItemView::PositionAtCenter, QAbstractItemView::PositionAtTop, QAbstractItemView::ScrollPerItem, QAbstractItemView::update(), verticalOffset(), QAbstractItemView::verticalScrollMode, and QSpanCollection::Span::width().

Referenced by QTableWidget::scrollToItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ selectColumn

void QTableView::selectColumn ( int column)
slot

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

See also
selectRow()

Definition at line 3186 of file qtableview.cpp.

References d.

Referenced by setSortingEnabled().

+ Here is the caller graph for this function:

◆ selectedIndexes()

QModelIndexList QTableView::selectedIndexes ( ) const
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2218 of file qtableview.cpp.

References d, i, and isIndexHidden().

+ Here is the call graph for this function:

◆ selectionChanged()

void QTableView::selectionChanged ( const QItemSelection & selected,
const QItemSelection & deselected )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 3510 of file qtableview.cpp.

References d, QItemSelection::indexes(), Q_UNUSED, and QAbstractItemView::selectionChanged().

+ Here is the call graph for this function:

◆ selectRow

void QTableView::selectRow ( int row)
slot

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

See also
selectColumn()

Definition at line 3174 of file qtableview.cpp.

References d.

Referenced by setVerticalHeader().

+ Here is the caller graph for this function:

◆ setColumnHidden()

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

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

See also
setRowHidden()

Definition at line 2697 of file qtableview.cpp.

References d, and hide().

+ Here is the call graph for this function:

◆ setColumnWidth()

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

Sets the width of the given column to be width.

Definition at line 2639 of file qtableview.cpp.

References d.

◆ setGridStyle()

void QTableView::setGridStyle ( Qt::PenStyle style)

Definition at line 2793 of file qtableview.cpp.

References d.

◆ setHorizontalHeader()

void QTableView::setHorizontalHeader ( QHeaderView * header)

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

See also
horizontalHeader(), setVerticalHeader()

Definition at line 1366 of file qtableview.cpp.

References columnCountChanged(), columnMoved(), columnResized(), connect(), connection, d, disconnect(), QHeaderView::geometriesChanged(), header(), resizeColumnToContents(), QHeaderView::sectionCountChanged(), QHeaderView::sectionHandleDoubleClicked(), QHeaderView::sectionMoved(), QHeaderView::sectionResized(), setSortingEnabled(), and updateGeometries().

+ Here is the call graph for this function:

◆ setModel()

void QTableView::setModel ( QAbstractItemModel * model)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Reimplemented in QTableWidget.

Definition at line 1259 of file qtableview.cpp.

References QAbstractItemModel::columnsInserted(), QAbstractItemModel::columnsRemoved(), QObjectPrivate::connect(), connection, d, disconnect(), QAbstractItemView::model(), QAbstractItemModel::rowsInserted(), QAbstractItemModel::rowsRemoved(), QAbstractItemView::setModel(), QAbstractItemModelPrivate::staticEmptyModel(), QTableViewPrivate::updateSpanInsertedColumns(), QTableViewPrivate::updateSpanInsertedRows(), QTableViewPrivate::updateSpanRemovedColumns(), and QTableViewPrivate::updateSpanRemovedRows().

Referenced by QTableWidget::QTableWidget(), QTableWidget::QTableWidget(), main(), and QSqlTableModel_snippets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRootIndex()

void QTableView::setRootIndex ( const QModelIndex & index)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 1292 of file qtableview.cpp.

References d, QAbstractItemView::setRootIndex(), and viewport().

+ Here is the call graph for this function:

◆ setRowHeight()

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

Sets the height of the given row to be height.

Definition at line 2592 of file qtableview.cpp.

References d.

◆ setRowHidden()

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

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

See also
setColumnHidden()

Definition at line 2672 of file qtableview.cpp.

References d, and hide().

+ Here is the call graph for this function:

◆ setSelection()

void QTableView::setSelection ( const QRect & rect,
QItemSelectionModel::SelectionFlags command )
overrideprotectedvirtual

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

Implements QAbstractItemView.

Definition at line 2002 of file qtableview.cpp.

References QList< T >::append(), QModelIndex::column(), d, horizontalHeader(), indexAt(), QModelIndex::isValid(), it, QModelIndex::model(), qMax(), qMin(), rect, QList< T >::reserve(), QModelIndex::row(), QHeaderView::sectionsMoved(), selection, and verticalHeader().

+ Here is the call graph for this function:

◆ setSelectionModel()

void QTableView::setSelectionModel ( QItemSelectionModel * selectionModel)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 1318 of file qtableview.cpp.

References connect(), QItemSelectionModel::currentRowChanged(), d, disconnect(), Q_ASSERT, QAbstractItemView::selectionModel(), QAbstractItemView::setSelectionModel(), and QAbstractItemModel::submit().

+ Here is the call graph for this function:

◆ setShowGrid

void QTableView::setShowGrid ( bool show)
slot

Definition at line 2772 of file qtableview.cpp.

References d, and show().

Referenced by QtPrivate::QCalendarView::QCalendarView().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSortingEnabled()

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.

Definition at line 2726 of file qtableview.cpp.

References QObjectPrivate::connect(), connect(), connection, d, disconnect(), horizontalHeader(), QHeaderView::sectionEntered(), QHeaderView::sectionPressed(), selectColumn(), QHeaderView::setSortIndicatorShown(), sortByColumn(), QTableViewPrivate::sortIndicatorChanged(), and QHeaderView::sortIndicatorChanged().

Referenced by setHorizontalHeader(), and QTableWidget::setSortingEnabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSpan()

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

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

See also
rowSpan(), columnSpan()

Definition at line 3356 of file qtableview.cpp.

References columnSpan(), d, and rowSpan().

+ Here is the call graph for this function:

◆ setVerticalHeader()

void QTableView::setVerticalHeader ( QHeaderView * header)

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

See also
verticalHeader(), setHorizontalHeader()

Definition at line 1406 of file qtableview.cpp.

References connect(), connection, d, disconnect(), QHeaderView::geometriesChanged(), header(), resizeRowToContents(), rowCountChanged(), rowMoved(), rowResized(), QHeaderView::sectionCountChanged(), QHeaderView::sectionEntered(), QHeaderView::sectionHandleDoubleClicked(), QHeaderView::sectionMoved(), QHeaderView::sectionPressed(), QHeaderView::sectionResized(), selectRow(), and updateGeometries().

+ Here is the call graph for this function:

◆ setWordWrap()

void QTableView::setWordWrap ( bool on)

Definition at line 2816 of file qtableview.cpp.

References d, and QMetaObject::invokeMethod().

+ Here is the call graph for this function:

◆ showColumn

void QTableView::showColumn ( int column)
slot

Show the given column.

See also
hideColumn(), showRow()

Definition at line 3230 of file qtableview.cpp.

References d.

◆ showGrid()

bool QTableView::showGrid ( ) const

Definition at line 2766 of file qtableview.cpp.

References d.

◆ showRow

void QTableView::showRow ( int row)
slot

Show the given row.

See also
hideRow(), showColumn()

Definition at line 3219 of file qtableview.cpp.

References d.

◆ sizeHintForColumn()

int QTableView::sizeHintForColumn ( int column) const
overrideprotectedvirtual

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(), QHeaderView::resizeContentsPrecision()

Reimplemented from QAbstractItemView.

Definition at line 2489 of file qtableview.cpp.

References d, hint(), initViewItemOption(), isVisible(), QAbstractItemView::model(), QModelIndex::model(), and qMax().

Referenced by resizeColumnToContents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeHintForRow()

int QTableView::sizeHintForRow ( int row) const
overrideprotectedvirtual

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(), QHeaderView::resizeContentsPrecision()

Reimplemented from QAbstractItemView.

Definition at line 2400 of file qtableview.cpp.

References d, hint(), initViewItemOption(), QAbstractItemView::model(), QModelIndex::model(), and qMax().

Referenced by resizeRowToContents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sortByColumn

void QTableView::sortByColumn ( int column,
Qt::SortOrder order )
slot
Since
4.2

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

Definition at line 3302 of file qtableview.cpp.

References d.

Referenced by setSortingEnabled().

+ Here is the caller graph for this function:

◆ timerEvent()

void QTableView::timerEvent ( QTimerEvent * event)
overrideprotected

\reimp

Definition at line 3046 of file qtableview.cpp.

References columnViewportPosition(), columnWidth(), d, QRect::height(), horizontalHeader(), i, qMin(), rect, QHeaderViewPrivate::ResizeSection, rowViewportPosition(), QAbstractItemView::state(), QAbstractItemView::timerEvent(), QAbstractItemView::updateEditorGeometries(), updateGeometries(), and verticalHeader().

+ Here is the call graph for this function:

◆ updateGeometries()

void QTableView::updateGeometries ( )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2268 of file qtableview.cpp.

References d, QRect::height(), QSize::height(), QAbstractItemView::horizontalScrollMode, QMetaObject::invokeMethod(), QRect::left(), qMax(), qMin(), QRect::right(), QAbstractItemView::ScrollPerItem, QRect::top(), QAbstractItemView::updateGeometries(), QAbstractItemView::verticalScrollMode, QRect::width(), and QSize::width().

Referenced by columnCountChanged(), columnMoved(), QtPrivate::QCalendarView::internalUpdate(), rowMoved(), setHorizontalHeader(), setVerticalHeader(), and timerEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ verticalHeader()

QHeaderView * QTableView::verticalHeader ( ) const

Returns the table view's vertical header.

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

Definition at line 1355 of file qtableview.cpp.

References d.

Referenced by QtPrivate::QCalendarView::QCalendarView(), paintEvent(), setSelection(), timerEvent(), visualRegionForSelection(), and QTableWidget::visualRow().

+ Here is the caller graph for this function:

◆ verticalOffset()

int QTableView::verticalOffset ( ) const
overrideprotectedvirtual

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()

Implements QAbstractItemView.

Definition at line 1734 of file qtableview.cpp.

References d.

Referenced by paintEvent(), and scrollTo().

+ Here is the caller graph for this function:

◆ verticalScrollbarAction()

void QTableView::verticalScrollbarAction ( int action)
overrideprotectedvirtual

Reimplemented from QAbstractItemView.

Definition at line 3318 of file qtableview.cpp.

References QAbstractItemView::verticalScrollbarAction().

+ Here is the call graph for this function:

◆ viewportSizeHint()

QSize QTableView::viewportSizeHint ( ) const
overrideprotected

\reimp

Definition at line 1248 of file qtableview.cpp.

References d.

◆ visualRect()

QRect QTableView::visualRect ( const QModelIndex & index) const
overridevirtual

\reimp

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.

Implements QAbstractItemView.

Definition at line 2864 of file qtableview.cpp.

References columnViewportPosition(), columnWidth(), d, i, isIndexHidden(), rowHeight(), rowViewportPosition(), and showGrid.

Referenced by moveCursor(), QTableWidget::visualItemRect(), and visualRegionForSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visualRegionForSelection()

QRegion QTableView::visualRegionForSelection ( const QItemSelection & selection) const
overrideprotectedvirtual

\reimp

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.

Implements QAbstractItemView.

Definition at line 2124 of file qtableview.cpp.

References columnViewportPosition(), columnWidth(), d, horizontalHeader(), QRect::intersects(), QList< T >::isEmpty(), rowHeight(), rowViewportPosition(), QHeaderView::sectionsMoved(), selection, showGrid, verticalHeader(), and visualRect().

+ Here is the call graph for this function:

◆ wordWrap()

bool QTableView::wordWrap ( ) const

Definition at line 2826 of file qtableview.cpp.

References d.

Friends And Related Symbol Documentation

◆ QAccessibleItemView

friend class QAccessibleItemView
friend

Definition at line 143 of file qtableview.h.

Property Documentation

◆ gridStyle

QTableView::gridStyle
readwrite

the pen style used to draw the grid.

This property holds the style used when drawing the grid (see \l{showGrid}).

Definition at line 21 of file qtableview.h.

◆ showGrid

QTableView::showGrid
readwrite

whether the grid is shown

If this property is true a grid is drawn for the table; if the property is false, no grid is drawn. The default value is true.

Definition at line 20 of file qtableview.h.

Referenced by paintEvent(), visualRect(), and visualRegionForSelection().

◆ sortingEnabled

QTableView::sortingEnabled
readwrite

whether sorting is enabled

Since
4.2

If this property is true, sorting is enabled for the table. If this property is false, sorting is not enabled. The default value is false.

Note
. Setting the property to true with setSortingEnabled() immediately triggers a call to sortByColumn() with the current sort section and order.
See also
sortByColumn()

Definition at line 22 of file qtableview.h.

◆ wordWrap

QTableView::wordWrap
readwrite

the item text word-wrapping policy

Since
4.3

If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.

Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current \l{QAbstractItemView::}{textElideMode}.

Definition at line 23 of file qtableview.h.


The documentation for this class was generated from the following files: