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>.
|
The QTableWidget class provides an item-based table view with a default model. More...
#include <qtablewidget.h>
Public Slots | |
void | scrollToItem (const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint=EnsureVisible) |
Scrolls the view if necessary to ensure that the item is visible. | |
void | insertRow (int row) |
Inserts an empty row into the table at row. | |
void | insertColumn (int column) |
Inserts an empty column into the table at column. | |
void | removeRow (int row) |
Removes the row row and all its items from the table. | |
void | removeColumn (int column) |
Removes the column column and all its items from the table. | |
void | clear () |
Removes all items in the view. | |
void | clearContents () |
Public Slots inherited from QTableView | |
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) |
Signals | |
void | itemPressed (QTableWidgetItem *item) |
This signal is emitted whenever an item in the table is pressed. | |
void | itemClicked (QTableWidgetItem *item) |
This signal is emitted whenever an item in the table is clicked. | |
void | itemDoubleClicked (QTableWidgetItem *item) |
This signal is emitted whenever an item in the table is double clicked. | |
void | itemActivated (QTableWidgetItem *item) |
This signal is emitted when the specified item has been activated. | |
void | itemEntered (QTableWidgetItem *item) |
This signal is emitted when the mouse cursor enters an item. | |
void | itemChanged (QTableWidgetItem *item) |
This signal is emitted whenever the data of item has changed. | |
void | currentItemChanged (QTableWidgetItem *current, QTableWidgetItem *previous) |
This signal is emitted whenever the current item changes. | |
void | itemSelectionChanged () |
This signal is emitted whenever the selection changes. | |
void | cellPressed (int row, int column) |
void | cellClicked (int row, int column) |
void | cellDoubleClicked (int row, int column) |
void | cellActivated (int row, int column) |
void | cellEntered (int row, int column) |
void | cellChanged (int row, int column) |
void | currentCellChanged (int currentRow, int currentColumn, int previousRow, int previousColumn) |
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) |
Public Member Functions | |
QTableWidget (QWidget *parent=nullptr) | |
Creates a new table view with the given parent. | |
QTableWidget (int rows, int columns, QWidget *parent=nullptr) | |
Creates a new table view with the given rows and columns, and with the given parent. | |
~QTableWidget () | |
Destroys this QTableWidget. | |
void | setRowCount (int rows) |
Sets the number of rows in this table's model to rows. | |
int | rowCount () const |
Returns the number of rows. | |
void | setColumnCount (int columns) |
Sets the number of columns in this table's model to columns. | |
int | columnCount () const |
Returns the number of columns. | |
int | row (const QTableWidgetItem *item) const |
Returns the row for the item. | |
int | column (const QTableWidgetItem *item) const |
Returns the column for the item. | |
QTableWidgetItem * | item (int row, int column) const |
Returns the item for the given row and column if one has been set; otherwise returns \nullptr. | |
void | setItem (int row, int column, QTableWidgetItem *item) |
Sets the item for the given row and column to item. | |
QTableWidgetItem * | takeItem (int row, int column) |
Removes the item at row and column from the table without deleting it. | |
QList< QTableWidgetItem * > | items (const QMimeData *data) const |
Returns a list of pointers to the items contained in the data object. | |
QModelIndex | indexFromItem (const QTableWidgetItem *item) const |
Returns the QModelIndex associated with the given item. | |
QTableWidgetItem * | itemFromIndex (const QModelIndex &index) const |
Returns a pointer to the QTableWidgetItem associated with the given index. | |
QTableWidgetItem * | verticalHeaderItem (int row) const |
Returns the vertical header item for row row. | |
void | setVerticalHeaderItem (int row, QTableWidgetItem *item) |
Sets the vertical header item for row row to item. | |
QTableWidgetItem * | takeVerticalHeaderItem (int row) |
QTableWidgetItem * | horizontalHeaderItem (int column) const |
Returns the horizontal header item for column, column, if one has been set; otherwise returns \nullptr. | |
void | setHorizontalHeaderItem (int column, QTableWidgetItem *item) |
Sets the horizontal header item for column column to item. | |
QTableWidgetItem * | takeHorizontalHeaderItem (int column) |
void | setVerticalHeaderLabels (const QStringList &labels) |
Sets the vertical header labels using labels. | |
void | setHorizontalHeaderLabels (const QStringList &labels) |
Sets the horizontal header labels using labels. | |
int | currentRow () const |
Returns the row of the current item. | |
int | currentColumn () const |
Returns the column of the current item. | |
QTableWidgetItem * | currentItem () const |
Returns the current item. | |
void | setCurrentItem (QTableWidgetItem *item) |
Sets the current item to item. | |
void | setCurrentItem (QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command) |
void | setCurrentCell (int row, int column) |
void | setCurrentCell (int row, int column, QItemSelectionModel::SelectionFlags command) |
void | sortItems (int column, Qt::SortOrder order=Qt::AscendingOrder) |
Sorts all the rows in the table widget based on column and order. | |
void | setSortingEnabled (bool enable) |
bool | isSortingEnabled () const |
void | editItem (QTableWidgetItem *item) |
Starts editing the item if it is editable. | |
void | openPersistentEditor (QTableWidgetItem *item) |
Opens an editor for the give item. | |
void | closePersistentEditor (QTableWidgetItem *item) |
Closes the persistent editor for item. | |
bool | isPersistentEditorOpen (QTableWidgetItem *item) const |
QWidget * | cellWidget (int row, int column) const |
void | setCellWidget (int row, int column, QWidget *widget) |
void | removeCellWidget (int row, int column) |
void | setRangeSelected (const QTableWidgetSelectionRange &range, bool select) |
Selects or deselects the range depending on select. | |
QList< QTableWidgetSelectionRange > | selectedRanges () const |
Returns a list of all selected ranges. | |
QList< QTableWidgetItem * > | selectedItems () const |
Returns a list of all selected items. | |
QList< QTableWidgetItem * > | findItems (const QString &text, Qt::MatchFlags flags) const |
Finds items that matches the text using the given flags. | |
int | visualRow (int logicalRow) const |
Returns the visual row of the given logicalRow. | |
int | visualColumn (int logicalColumn) const |
Returns the visual column of the given logicalColumn. | |
QTableWidgetItem * | itemAt (const QPoint &p) const |
Returns a pointer to the item at the given point, or returns \nullptr if point is not covered by an item in the table widget. | |
QTableWidgetItem * | itemAt (int x, int y) const |
Returns the item at the position equivalent to QPoint({ax}, {ay}) in the table widget's coordinate system, or returns \nullptr if the specified point is not covered by an item in the table widget. | |
QRect | visualItemRect (const QTableWidgetItem *item) const |
Returns the rectangle on the viewport occupied by the item at item. | |
const QTableWidgetItem * | itemPrototype () const |
Returns the item prototype used by the table. | |
void | setItemPrototype (const QTableWidgetItem *item) |
Sets the item prototype for the table to the specified item. | |
bool | isPersistentEditorOpen (const QModelIndex &index) const |
Public Member Functions inherited from QTableView | |
QTableView (QWidget *parent=nullptr) | |
Constructs a table view with a parent to represent the data. | |
~QTableView () | |
Destroys the table view. | |
void | setRootIndex (const QModelIndex &index) override |
\reimp | |
void | setSelectionModel (QItemSelectionModel *selectionModel) override |
\reimp | |
void | doItemsLayout () override |
QHeaderView * | horizontalHeader () const |
Returns the table view's horizontal header. | |
QHeaderView * | verticalHeader () 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. | |
QAbstractItemModel * | model () const |
Returns the model that this view is presenting. | |
QItemSelectionModel * | selectionModel () const |
Returns the current selection model. | |
void | setItemDelegate (QAbstractItemDelegate *delegate) |
Sets the item delegate for this view and its model to delegate. | |
QAbstractItemDelegate * | itemDelegate () 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) |
QWidget * | indexWidget (const QModelIndex &index) const |
void | setItemDelegateForRow (int row, QAbstractItemDelegate *delegate) |
QAbstractItemDelegate * | itemDelegateForRow (int row) const |
void | setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate) |
QAbstractItemDelegate * | itemDelegateForColumn (int column) const |
virtual QAbstractItemDelegate * | itemDelegateForIndex (const QModelIndex &index) const |
virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query) const override |
\reimp | |
Protected Member Functions | |
bool | event (QEvent *e) override |
\reimp | |
virtual QStringList | mimeTypes () const |
Returns a list of MIME types that can be used to describe a list of tablewidget items. | |
virtual QMimeData * | mimeData (const QList< QTableWidgetItem * > &items) const |
Returns an object that contains a serialized description of the specified items. | |
virtual bool | dropMimeData (int row, int column, const QMimeData *data, Qt::DropAction action) |
Handles the data supplied by a drag and drop operation that ended with the given action in the given row and column. | |
virtual Qt::DropActions | supportedDropActions () const |
Returns the drop actions supported by this view. | |
Protected Member Functions inherited from QTableView | |
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 ¤t, 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 ®ion) |
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 | |
int | rowCount |
the number of rows in the table | |
int | columnCount |
the number of columns in the table | |
Properties inherited from QTableView | |
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 | |
Private Member Functions | |
void | setModel (QAbstractItemModel *model) override |
Friends | |
class | QTableModel |
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 } |
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... | |
Protected Slots inherited from QTableView | |
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. | |
The QTableWidget class provides an item-based table view with a default model.
\inmodule QtWidgets
Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem.
If you want a table that uses your own data model you should use QTableView rather than this class.
Table widgets can be constructed with the required numbers of rows and columns:
Alternatively, tables can be constructed without a given size and resized later:
Items are created outside the table (with no parent widget) and inserted into the table with setItem():
If you want to enable sorting in your table widget, do so after you have populated it with items, otherwise sorting may interfere with the insertion order (see setItem() for details).
Tables can be given both horizontal and vertical headers. The simplest way to create the headers is to supply a list of strings to the setHorizontalHeaderLabels() and setVerticalHeaderLabels() functions. These will provide simple textual headers for the table's columns and rows. More sophisticated headers can be created from existing table items that are usually constructed outside the table. For example, we can construct a table item with an icon and aligned text, and use it as the header for a particular column:
The number of rows in the table can be found with rowCount(), and the number of columns with columnCount(). The table can be cleared with the clear() function.
Definition at line 192 of file qtablewidget.h.
Creates a new table view with the given parent.
Definition at line 1871 of file qtablewidget.cpp.
References d, QTableModel, and QTableView::setModel().
Creates a new table view with the given rows and columns, and with the given parent.
Definition at line 1882 of file qtablewidget.cpp.
References d, QTableModel, and QTableView::setModel().
QTableWidget::~QTableWidget | ( | ) |
|
signal |
This signal is emitted when the cell specified by row and column has been activated
|
signal |
This signal is emitted whenever the data of the item in the cell specified by row and column has changed.
|
signal |
This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.
|
signal |
This signal is emitted whenever a cell in the table is double clicked. The row and column specified is the cell that was double clicked.
|
signal |
This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column.
This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.
|
signal |
This signal is emitted whenever a cell in the table is pressed. The row and column specified is the cell that was pressed.
QWidget * QTableWidget::cellWidget | ( | int | row, |
int | column ) const |
Returns the widget displayed in the cell in the given row and column.
Definition at line 2309 of file qtablewidget.cpp.
References QAbstractItemModel::index(), QAbstractItemView::indexWidget(), and QAbstractItemView::model().
|
slot |
Removes all items in the view.
This will also remove all selections and headers. If you don't want to remove the headers, use QTableWidget::clearContents(). The table dimensions stay the same.
Definition at line 2551 of file qtablewidget.cpp.
References QItemSelectionModel::clear(), d, and QAbstractItemView::selectionModel().
|
slot |
Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.
Definition at line 2565 of file qtablewidget.cpp.
References QItemSelectionModel::clear(), d, and QAbstractItemView::selectionModel().
void QTableWidget::closePersistentEditor | ( | QTableWidgetItem * | item | ) |
Closes the persistent editor for item.
Definition at line 2277 of file qtablewidget.cpp.
References QAbstractItemView::closePersistentEditor(), d, and item.
int QTableWidget::column | ( | const QTableWidgetItem * | item | ) | const |
Returns the column for the item.
Definition at line 1957 of file qtablewidget.cpp.
Referenced by QTableWidgetItem::column().
int QTableWidget::columnCount | ( | ) | const |
|
signal |
This signal is emitted whenever the current cell changes. The cell specified by previousRow and previousColumn is the cell that previously had the focus, the cell specified by currentRow and currentColumn is the new current cell.
int QTableWidget::currentColumn | ( | ) | const |
Returns the column of the current item.
Definition at line 2147 of file qtablewidget.cpp.
References QModelIndex::column(), and QAbstractItemView::currentIndex().
QTableWidgetItem * QTableWidget::currentItem | ( | ) | const |
Returns the current item.
Definition at line 2157 of file qtablewidget.cpp.
References QAbstractItemView::currentIndex(), and d.
Referenced by MainWindow::averageItems(), and MainWindow::sumItems().
|
signal |
This signal is emitted whenever the current item changes.
The previous item is the item that previously had the focus, current is the new current item.
int QTableWidget::currentRow | ( | ) | const |
Returns the row of the current item.
Definition at line 2137 of file qtablewidget.cpp.
References QAbstractItemView::currentIndex(), and QModelIndex::row().
|
protectedvirtual |
Handles the data supplied by a drag and drop operation that ended with the given action in the given row and column.
Returns true
if the data and action can be handled by the model; otherwise returns false
.
Definition at line 2620 of file qtablewidget.cpp.
References QAbstractItemModel::index(), and QAbstractItemView::model().
void QTableWidget::editItem | ( | QTableWidgetItem * | item | ) |
Starts editing the item if it is editable.
Definition at line 2250 of file qtablewidget.cpp.
|
overrideprotected |
\reimp
Definition at line 2689 of file qtablewidget.cpp.
References QAbstractItemView::event().
QList< QTableWidgetItem * > QTableWidget::findItems | ( | const QString & | text, |
Qt::MatchFlags | flags ) const |
Finds items that matches the text using the given flags.
Definition at line 2400 of file qtablewidget.cpp.
References QList< T >::append(), QList< T >::at(), columnCount, d, Qt::DisplayRole, i, QAbstractItemModel::index(), items, QAbstractItemView::model(), QList< T >::reserve(), QList< T >::size(), and text.
QTableWidgetItem * QTableWidget::horizontalHeaderItem | ( | int | column | ) | const |
Returns the horizontal header item for column, column, if one has been set; otherwise returns \nullptr.
Definition at line 2061 of file qtablewidget.cpp.
References d.
QModelIndex QTableWidget::indexFromItem | ( | const QTableWidgetItem * | item | ) | const |
Returns the QModelIndex associated with the given item.
{const} item. Definition at line 2664 of file qtablewidget.cpp.
Referenced by mimeData().
|
slot |
Inserts an empty column into the table at column.
Definition at line 2519 of file qtablewidget.cpp.
References d.
|
slot |
Inserts an empty row into the table at row.
Definition at line 2510 of file qtablewidget.cpp.
References d.
bool QAbstractItemView::isPersistentEditorOpen | ( | const QModelIndex & | index | ) | const |
Returns whether a persistent editor is open for the item at index index.
Definition at line 182 of file qabstractitemview.cpp.
bool QTableWidget::isPersistentEditorOpen | ( | QTableWidgetItem * | item | ) | const |
Returns whether a persistent editor is open for item item.
Definition at line 2293 of file qtablewidget.cpp.
References d, QAbstractItemView::isPersistentEditorOpen(), and item.
bool QTableWidget::isSortingEnabled | ( | ) | const |
Definition at line 2241 of file qtablewidget.cpp.
References QTableView::isSortingEnabled().
QTableWidgetItem * QTableWidget::item | ( | int | row, |
int | column ) const |
Returns the item for the given row and column if one has been set; otherwise returns \nullptr.
Definition at line 1970 of file qtablewidget.cpp.
References d.
|
signal |
This signal is emitted when the specified item has been activated.
QTableWidgetItem * QTableWidget::itemAt | ( | const QPoint & | point | ) | const |
Returns a pointer to the item at the given point, or returns \nullptr if point is not covered by an item in the table widget.
Definition at line 2442 of file qtablewidget.cpp.
References d, and QTableView::indexAt().
Referenced by itemAt().
|
inline |
Returns the item at the position equivalent to QPoint({ax}, {ay}) in the table widget's coordinate system, or returns \nullptr if the specified point is not covered by an item in the table widget.
Definition at line 320 of file qtablewidget.h.
References itemAt().
|
signal |
This signal is emitted whenever the data of item has changed.
|
signal |
This signal is emitted whenever an item in the table is clicked.
The item specified is the item that was clicked.
|
signal |
This signal is emitted whenever an item in the table is double clicked.
The item specified is the item that was double clicked.
|
signal |
This signal is emitted when the mouse cursor enters an item.
The item is the item entered.
This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.
QTableWidgetItem * QTableWidget::itemFromIndex | ( | const QModelIndex & | index | ) | const |
Returns a pointer to the QTableWidgetItem associated with the given index.
Definition at line 2674 of file qtablewidget.cpp.
References d.
|
signal |
This signal is emitted whenever an item in the table is pressed.
The item specified is the item that was pressed.
const QTableWidgetItem * QTableWidget::itemPrototype | ( | ) | const |
Returns the item prototype used by the table.
Definition at line 2482 of file qtablewidget.cpp.
References d.
QList< QTableWidgetItem * > QTableWidget::items | ( | const QMimeData * | data | ) | const |
Returns a list of pointers to the items contained in the data object.
If the object was not created by a QTreeWidget in the same process, the list is empty.
Definition at line 2650 of file qtablewidget.cpp.
|
signal |
This signal is emitted whenever the selection changes.
Referenced by QTableWidgetPrivate::setup().
|
protectedvirtual |
Returns an object that contains a serialized description of the specified items.
The format used to describe the items is obtained from the mimeTypes() function.
If the list of items is empty, \nullptr is returned rather than a serialized empty list.
Definition at line 2591 of file qtablewidget.cpp.
References QList< T >::clear(), d, indexFromItem(), QList< T >::isEmpty(), item, items, QList< T >::reserve(), and QList< T >::size().
|
protectedvirtual |
Returns a list of MIME types that can be used to describe a list of tablewidget items.
Definition at line 2578 of file qtablewidget.cpp.
void QTableWidget::openPersistentEditor | ( | QTableWidgetItem * | item | ) |
Opens an editor for the give item.
The editor remains open after editing.
Definition at line 2263 of file qtablewidget.cpp.
References d, item, and QAbstractItemView::openPersistentEditor().
|
inline |
Removes the widget set on the cell indicated by row and column.
Definition at line 317 of file qtablewidget.h.
References setCellWidget().
|
slot |
Removes the column column and all its items from the table.
Definition at line 2537 of file qtablewidget.cpp.
References d.
|
slot |
Removes the row row and all its items from the table.
Definition at line 2528 of file qtablewidget.cpp.
References d.
int QTableWidget::row | ( | const QTableWidgetItem * | item | ) | const |
Returns the row for the item.
Definition at line 1948 of file qtablewidget.cpp.
Referenced by QTableWidgetItem::row().
int QTableWidget::rowCount | ( | ) | const |
|
slot |
Scrolls the view if necessary to ensure that the item is visible.
The hint parameter specifies more precisely where the item should be located after the operation.
Definition at line 2467 of file qtablewidget.cpp.
References d, hint(), item, Q_ASSERT, and QTableView::scrollTo().
QList< QTableWidgetItem * > QTableWidget::selectedItems | ( | ) | const |
Returns a list of all selected items.
This function returns a list of pointers to the contents of the selected cells. Use the selectedIndexes() function to retrieve the complete selection including empty cells.
Definition at line 2381 of file qtablewidget.cpp.
References QList< T >::append(), d, QTableView::isIndexHidden(), item, items, QItemSelectionModel::selectedIndexes, and QAbstractItemView::selectionModel().
Referenced by MainWindow::averageItems(), and MainWindow::sumItems().
QList< QTableWidgetSelectionRange > QTableWidget::selectedRanges | ( | ) | const |
Returns a list of all selected ranges.
Definition at line 2357 of file qtablewidget.cpp.
References i, QItemSelectionModel::selection, and QAbstractItemView::selectionModel().
Sets the given widget to be displayed in the cell in the given row and column, passing the ownership of the widget to the table.
If cell widget A is replaced with cell widget B, cell widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.
Definition at line 2329 of file qtablewidget.cpp.
References QAbstractItemModel::index(), QAbstractItemView::model(), QAbstractItemView::setIndexWidget(), and widget.
Referenced by removeCellWidget().
void QTableWidget::setColumnCount | ( | int | columns | ) |
Sets the number of columns in this table's model to columns.
If this is less than columnCount(), the data in the unwanted columns is discarded.
Definition at line 1929 of file qtablewidget.cpp.
References d.
void QTableWidget::setCurrentCell | ( | int | row, |
int | column ) |
Sets the current cell to be the cell at position (row, column).
Depending on the current \l{QAbstractItemView::SelectionMode}{selection mode}, the cell may also be selected.
Definition at line 2201 of file qtablewidget.cpp.
References QAbstractItemView::model(), and QAbstractItemView::setCurrentIndex().
void QTableWidget::setCurrentCell | ( | int | row, |
int | column, | ||
QItemSelectionModel::SelectionFlags | command ) |
Sets the current cell to be the cell at position (row, column), using the given command.
Definition at line 2214 of file qtablewidget.cpp.
References d, and QAbstractItemView::model().
void QTableWidget::setCurrentItem | ( | QTableWidgetItem * | item | ) |
Sets the current item to item.
Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, the item is also selected.
Definition at line 2171 of file qtablewidget.cpp.
References d, item, and QAbstractItemView::setCurrentIndex().
void QTableWidget::setCurrentItem | ( | QTableWidgetItem * | item, |
QItemSelectionModel::SelectionFlags | command ) |
Sets the current item to be item, using the given command.
Definition at line 2184 of file qtablewidget.cpp.
void QTableWidget::setHorizontalHeaderItem | ( | int | column, |
QTableWidgetItem * | item ) |
Sets the horizontal header item for column column to item.
If necessary, the column count is increased to fit the item. The previous header item (if there was one) is deleted.
Definition at line 2072 of file qtablewidget.cpp.
References d, item, and takeHorizontalHeaderItem().
Referenced by setHorizontalHeaderLabels().
void QTableWidget::setHorizontalHeaderLabels | ( | const QStringList & | labels | ) |
Sets the horizontal header labels using labels.
Definition at line 2117 of file qtablewidget.cpp.
References QAbstractItemModel::columnCount(), d, i, item, QAbstractItemView::model(), and setHorizontalHeaderItem().
void QTableWidget::setItem | ( | int | row, |
int | column, | ||
QTableWidgetItem * | item ) |
Sets the item for the given row and column to item.
The table takes ownership of the item.
Note that if sorting is enabled (see \l{QTableView::sortingEnabled} {sortingEnabled}) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).
Definition at line 1994 of file qtablewidget.cpp.
References d, item, Q_UNLIKELY, qWarning, and takeItem().
Referenced by MainWindow::showTable().
void QTableWidget::setItemPrototype | ( | const QTableWidgetItem * | item | ) |
Sets the item prototype for the table to the specified item.
The table widget will use the item prototype clone function when it needs to create a new table item. For example when the user is editing in an empty cell. This is useful when you have a QTableWidgetItem subclass and want to make sure that QTableWidget creates instances of your subclass.
The table takes ownership of the prototype.
Definition at line 2501 of file qtablewidget.cpp.
|
overrideprivatevirtual |
Reimplemented from QTableView.
Definition at line 2683 of file qtablewidget.cpp.
References Q_ASSERT.
void QTableWidget::setRangeSelected | ( | const QTableWidgetSelectionRange & | range, |
bool | select ) |
Selects or deselects the range depending on select.
Definition at line 2338 of file qtablewidget.cpp.
References QItemSelectionModel::Deselect, QAbstractItemModel::index(), QAbstractItemView::model(), QAbstractItemView::rootIndex(), QItemSelectionModel::Select, QItemSelectionModel::select(), select(), and QAbstractItemView::selectionModel().
void QTableWidget::setRowCount | ( | int | rows | ) |
Sets the number of rows in this table's model to rows.
If this is less than rowCount(), the data in the unwanted rows is discarded.
Definition at line 1906 of file qtablewidget.cpp.
References d.
void QTableWidget::setSortingEnabled | ( | bool | enable | ) |
Definition at line 2233 of file qtablewidget.cpp.
References QTableView::setSortingEnabled().
void QTableWidget::setVerticalHeaderItem | ( | int | row, |
QTableWidgetItem * | item ) |
Sets the vertical header item for row row to item.
Definition at line 2033 of file qtablewidget.cpp.
References d, item, and takeVerticalHeaderItem().
Referenced by setVerticalHeaderLabels().
void QTableWidget::setVerticalHeaderLabels | ( | const QStringList & | labels | ) |
Sets the vertical header labels using labels.
Definition at line 2099 of file qtablewidget.cpp.
References d, i, item, QAbstractItemView::model(), QAbstractItemModel::rowCount(), and setVerticalHeaderItem().
void QTableWidget::sortItems | ( | int | column, |
Qt::SortOrder | order = Qt::AscendingOrder ) |
Sorts all the rows in the table widget based on column and order.
Definition at line 2223 of file qtablewidget.cpp.
References d, QTableView::horizontalHeader(), and QHeaderView::setSortIndicator().
|
protectedvirtual |
Returns the drop actions supported by this view.
Definition at line 2639 of file qtablewidget.cpp.
References Qt::MoveAction.
QTableWidgetItem * QTableWidget::takeHorizontalHeaderItem | ( | int | column | ) |
Definition at line 2087 of file qtablewidget.cpp.
References d, and QTableModel::takeHorizontalHeaderItem().
Referenced by setHorizontalHeaderItem().
QTableWidgetItem * QTableWidget::takeItem | ( | int | row, |
int | column ) |
Removes the item at row and column from the table without deleting it.
Definition at line 2012 of file qtablewidget.cpp.
Referenced by setItem().
QTableWidgetItem * QTableWidget::takeVerticalHeaderItem | ( | int | row | ) |
Definition at line 2048 of file qtablewidget.cpp.
References d, and QTableModel::takeVerticalHeaderItem().
Referenced by setVerticalHeaderItem().
QTableWidgetItem * QTableWidget::verticalHeaderItem | ( | int | row | ) | const |
Returns the vertical header item for row row.
Definition at line 2024 of file qtablewidget.cpp.
References d.
int QTableWidget::visualColumn | ( | int | logicalColumn | ) | const |
Returns the visual column of the given logicalColumn.
Definition at line 2428 of file qtablewidget.cpp.
References QTableView::horizontalHeader(), and QHeaderView::visualIndex().
QRect QTableWidget::visualItemRect | ( | const QTableWidgetItem * | item | ) | const |
Returns the rectangle on the viewport occupied by the item at item.
Definition at line 2451 of file qtablewidget.cpp.
References d, item, Q_ASSERT, and QTableView::visualRect().
int QTableWidget::visualRow | ( | int | logicalRow | ) | const |
Returns the visual row of the given logicalRow.
Definition at line 2419 of file qtablewidget.cpp.
References QTableView::verticalHeader(), and QHeaderView::visualIndex().
|
friend |
Definition at line 198 of file qtablewidget.h.
Referenced by QTableWidget(), and QTableWidget().
|
readwrite |
the number of columns in the table
By default, for a table constructed without row and column counts, this property contains a value of 0.
Definition at line 196 of file qtablewidget.h.
Referenced by findItems().
|
readwrite |
the number of rows in the table
By default, for a table constructed without row and column counts, this property contains a value of 0.
Definition at line 195 of file qtablewidget.h.