Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QTableWidget Class Reference

The QTableWidget class provides an item-based table view with a default model. More...

#include <qtablewidget.h>

+ Inheritance diagram for QTableWidget:
+ Collaboration diagram for QTableWidget:

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 setRootIndex (const QModelIndex &index)
 Sets the root item to the item at the given index.
 
virtual void doItemsLayout ()
 
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.
 
QTableWidgetItemitem (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.
 
QTableWidgetItemtakeItem (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.
 
QTableWidgetItemitemFromIndex (const QModelIndex &index) const
 Returns a pointer to the QTableWidgetItem associated with the given index.
 
QTableWidgetItemverticalHeaderItem (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.
 
QTableWidgetItemtakeVerticalHeaderItem (int row)
 
QTableWidgetItemhorizontalHeaderItem (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.
 
QTableWidgetItemtakeHorizontalHeaderItem (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.
 
QTableWidgetItemcurrentItem () 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
 
QWidgetcellWidget (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< QTableWidgetSelectionRangeselectedRanges () 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.
 
QTableWidgetItemitemAt (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.
 
QTableWidgetItemitemAt (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 QTableWidgetItemitemPrototype () 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 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.
 
virtual void setModel (QAbstractItemModel *model)
 Sets the model for the view to present.
 
QAbstractItemModelmodel () const
 Returns the model that this view is presenting.
 
virtual void setSelectionModel (QItemSelectionModel *selectionModel)
 Sets the current selection model to the given selectionModel.
 
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.
 
virtual QRect visualRect (const QModelIndex &index) const =0
 Returns the rectangle on the viewport occupied by the item at index.
 
virtual void scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
 Scrolls the view if necessary to ensure that the item at index is visible.
 
virtual QModelIndex indexAt (const QPoint &point) const =0
 Returns the model index of the item at the viewport coordinates point.
 
QSize sizeHintForIndex (const QModelIndex &index) const
 Returns the size hint for the item with the specified index or an invalid size for invalid indexes.
 
virtual int sizeHintForRow (int row) const
 Returns the height size hint for the specified row or -1 if there is no model.
 
virtual int sizeHintForColumn (int column) const
 Returns the width size hint for the specified column or -1 if there is no model.
 
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 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 QMimeDatamimeData (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 &current, const QModelIndex &previous) override
 \reimp
 
- Protected Member Functions inherited from QAbstractItemView
 QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=nullptr)
 
virtual QModelIndex moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0
 Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction and keyboard modifiers specified by modifiers.
 
virtual int horizontalOffset () const =0
 Returns the horizontal offset of the view.
 
virtual int verticalOffset () const =0
 Returns the vertical offset of the view.
 
virtual bool isIndexHidden (const QModelIndex &index) const =0
 Returns true if the item referred to by the given index is hidden in the view, otherwise returns false.
 
virtual void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command)=0
 Applies the selection flags to the items in or touched by the rectangle, rect.
 
virtual QRegion visualRegionForSelection (const QItemSelection &selection) const =0
 Returns the region from the viewport of the items in the given selection.
 
virtual QModelIndexList selectedIndexes () const
 This convenience function returns a list of all selected and non-hidden item indexes in the view.
 
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.
 
virtual void initViewItemOption (QStyleOptionViewItem *option) const
 
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

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 selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 This slot is called when the selection is changed.
 
virtual void currentChanged (const QModelIndex &current, const QModelIndex &previous)
 This slot is called when a new item becomes the current item.
 
virtual void updateEditorData ()
 
virtual void updateEditorGeometries ()
 
virtual void updateGeometries ()
 
virtual void verticalScrollbarAction (int action)
 
virtual void horizontalScrollbarAction (int action)
 
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.
 

Detailed Description

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:

tableWidget = new QTableWidget(12, 3, this);
The QTableWidget class provides an item-based table view with a default model.

Alternatively, tables can be constructed without a given size and resized later:

tableWidget = new QTableWidget(this);
tableWidget->setRowCount(10);
tableWidget->setColumnCount(5);

Items are created outside the table (with no parent widget) and inserted into the table with setItem():

QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
(row+1)*(column+1)));
tableWidget->setItem(row, column, newItem);
The QTableWidgetItem class provides an item for use with the QTableWidget class.
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
SSL_CTX int(*) void arg)
#define tr(X)

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:

QTableWidgetItem *cubesHeaderItem = new QTableWidgetItem(tr("Cubes"));
cubesHeaderItem->setIcon(QIcon(QPixmap(":/Images/cubed.png")));
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
void setTextAlignment(Qt::Alignment alignment)
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument.
void setIcon(const QIcon &icon)
Sets the item's icon to the icon specified.
@ AlignVCenter
Definition qnamespace.h:154

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.

See also
QTableWidgetItem, QTableView, {Model/View Programming}

Definition at line 192 of file qtablewidget.h.

Constructor & Destructor Documentation

◆ QTableWidget() [1/2]

QTableWidget::QTableWidget ( QWidget parent = nullptr)
explicit

Creates a new table view with the given parent.

Definition at line 1859 of file qtablewidget.cpp.

References d, QTableModel, and QTableView::setModel().

+ Here is the call graph for this function:

◆ QTableWidget() [2/2]

QTableWidget::QTableWidget ( int  rows,
int  columns,
QWidget parent = nullptr 
)

Creates a new table view with the given rows and columns, and with the given parent.

Definition at line 1870 of file qtablewidget.cpp.

References d, QTableModel, and QTableView::setModel().

+ Here is the call graph for this function:

◆ ~QTableWidget()

QTableWidget::~QTableWidget ( )

Destroys this QTableWidget.

Definition at line 1881 of file qtablewidget.cpp.

Member Function Documentation

◆ cellActivated

void QTableWidget::cellActivated ( int  row,
int  column 
)
signal
Since
4.1

This signal is emitted when the cell specified by row and column has been activated

◆ cellChanged

void QTableWidget::cellChanged ( int  row,
int  column 
)
signal
Since
4.1

This signal is emitted whenever the data of the item in the cell specified by row and column has changed.

◆ cellClicked

void QTableWidget::cellClicked ( int  row,
int  column 
)
signal
Since
4.1

This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.

◆ cellDoubleClicked

void QTableWidget::cellDoubleClicked ( int  row,
int  column 
)
signal
Since
4.1

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.

◆ cellEntered

void QTableWidget::cellEntered ( int  row,
int  column 
)
signal
Since
4.1

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.

◆ cellPressed

void QTableWidget::cellPressed ( int  row,
int  column 
)
signal
Since
4.1

This signal is emitted whenever a cell in the table is pressed. The row and column specified is the cell that was pressed.

◆ cellWidget()

QWidget * QTableWidget::cellWidget ( int  row,
int  column 
) const
Since
4.1

Returns the widget displayed in the cell in the given row and column.

Note
The table takes ownership of the widget.
See also
setCellWidget()

Definition at line 2295 of file qtablewidget.cpp.

References QAbstractItemModel::index(), QAbstractItemView::indexWidget(), and QAbstractItemView::model().

+ Here is the call graph for this function:

◆ clear

void QTableWidget::clear ( )
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 2537 of file qtablewidget.cpp.

References QItemSelectionModel::clear(), d, and QAbstractItemView::selectionModel().

+ Here is the call graph for this function:

◆ clearContents

void QTableWidget::clearContents ( )
slot
Since
4.2

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 2551 of file qtablewidget.cpp.

References QItemSelectionModel::clear(), d, and QAbstractItemView::selectionModel().

+ Here is the call graph for this function:

◆ closePersistentEditor()

void QTableWidget::closePersistentEditor ( QTableWidgetItem item)

Closes the persistent editor for item.

See also
openPersistentEditor(), isPersistentEditorOpen()

Definition at line 2263 of file qtablewidget.cpp.

References QAbstractItemView::closePersistentEditor(), d, and item.

+ Here is the call graph for this function:

◆ column()

int QTableWidget::column ( const QTableWidgetItem item) const

Returns the column for the item.

Definition at line 1943 of file qtablewidget.cpp.

References d, and item.

◆ columnCount()

int QTableWidget::columnCount ( ) const

Returns the number of columns.

Definition at line 1925 of file qtablewidget.cpp.

References d.

◆ currentCellChanged

void QTableWidget::currentCellChanged ( int  currentRow,
int  currentColumn,
int  previousRow,
int  previousColumn 
)
signal
Since
4.1

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.

◆ currentColumn()

int QTableWidget::currentColumn ( ) const

Returns the column of the current item.

See also
currentRow(), setCurrentCell()

Definition at line 2133 of file qtablewidget.cpp.

References QModelIndex::column(), and QAbstractItemView::currentIndex().

+ Here is the call graph for this function:

◆ currentItem()

QTableWidgetItem * QTableWidget::currentItem ( ) const

Returns the current item.

See also
setCurrentItem()

Definition at line 2143 of file qtablewidget.cpp.

References QAbstractItemView::currentIndex(), and d.

Referenced by MainWindow::averageItems(), and MainWindow::sumItems().

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

◆ currentItemChanged

void QTableWidget::currentItemChanged ( QTableWidgetItem current,
QTableWidgetItem previous 
)
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.

◆ currentRow()

int QTableWidget::currentRow ( ) const

Returns the row of the current item.

See also
currentColumn(), setCurrentCell()

Definition at line 2123 of file qtablewidget.cpp.

References QAbstractItemView::currentIndex(), and QModelIndex::row().

+ Here is the call graph for this function:

◆ dropMimeData()

bool QTableWidget::dropMimeData ( int  row,
int  column,
const QMimeData data,
Qt::DropAction  action 
)
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.

See also
supportedDropActions()

Definition at line 2606 of file qtablewidget.cpp.

References QAbstractItemModel::index(), and QAbstractItemView::model().

+ Here is the call graph for this function:

◆ editItem()

void QTableWidget::editItem ( QTableWidgetItem item)

Starts editing the item if it is editable.

Definition at line 2236 of file qtablewidget.cpp.

References d, QAbstractItemView::edit(), and item.

+ Here is the call graph for this function:

◆ event()

bool QTableWidget::event ( QEvent e)
overrideprotected

\reimp

Definition at line 2675 of file qtablewidget.cpp.

References e, and QAbstractItemView::event().

+ Here is the call graph for this function:

◆ findItems()

QList< QTableWidgetItem * > QTableWidget::findItems ( const QString text,
Qt::MatchFlags  flags 
) const

Finds items that matches the text using the given flags.

Definition at line 2386 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.

+ Here is the call graph for this function:

◆ horizontalHeaderItem()

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 2047 of file qtablewidget.cpp.

References d.

◆ indexFromItem()

QModelIndex QTableWidget::indexFromItem ( const QTableWidgetItem item) const

Returns the QModelIndex associated with the given item.

Note
In Qt versions prior to 5.10, this function took a non-{const} item.

Definition at line 2650 of file qtablewidget.cpp.

References d, and item.

Referenced by mimeData().

+ Here is the caller graph for this function:

◆ insertColumn

void QTableWidget::insertColumn ( int  column)
slot

Inserts an empty column into the table at column.

Definition at line 2505 of file qtablewidget.cpp.

References d.

◆ insertRow

void QTableWidget::insertRow ( int  row)
slot

Inserts an empty row into the table at row.

Definition at line 2496 of file qtablewidget.cpp.

References d.

◆ isPersistentEditorOpen() [1/2]

bool QAbstractItemView::isPersistentEditorOpen ( const QModelIndex index) const
Since
5.10

Returns whether a persistent editor is open for the item at index index.

See also
openPersistentEditor(), closePersistentEditor()

Definition at line 182 of file qabstractitemview.cpp.

◆ isPersistentEditorOpen() [2/2]

bool QTableWidget::isPersistentEditorOpen ( QTableWidgetItem item) const
Since
5.10

Returns whether a persistent editor is open for item item.

See also
openPersistentEditor(), closePersistentEditor()

Definition at line 2279 of file qtablewidget.cpp.

References d, QAbstractItemView::isPersistentEditorOpen(), and item.

+ Here is the call graph for this function:

◆ isSortingEnabled()

bool QTableWidget::isSortingEnabled ( ) const

Definition at line 2227 of file qtablewidget.cpp.

References QTableView::isSortingEnabled().

+ Here is the call graph for this function:

◆ item()

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.

See also
setItem()

Definition at line 1956 of file qtablewidget.cpp.

References d.

◆ itemActivated

void QTableWidget::itemActivated ( QTableWidgetItem item)
signal

This signal is emitted when the specified item has been activated.

◆ itemAt() [1/2]

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.

See also
item()

Definition at line 2428 of file qtablewidget.cpp.

References d, and QTableView::indexAt().

+ Here is the call graph for this function:

◆ itemAt() [2/2]

QTableWidgetItem * QTableWidget::itemAt ( int  ax,
int  ay 
) const
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.

See also
item()

Definition at line 330 of file qtablewidget.h.

◆ itemChanged

void QTableWidget::itemChanged ( QTableWidgetItem item)
signal

This signal is emitted whenever the data of item has changed.

◆ itemClicked

void QTableWidget::itemClicked ( QTableWidgetItem item)
signal

This signal is emitted whenever an item in the table is clicked.

The item specified is the item that was clicked.

◆ itemDoubleClicked

void QTableWidget::itemDoubleClicked ( QTableWidgetItem item)
signal

This signal is emitted whenever an item in the table is double clicked.

The item specified is the item that was double clicked.

◆ itemEntered

void QTableWidget::itemEntered ( QTableWidgetItem item)
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.

◆ itemFromIndex()

QTableWidgetItem * QTableWidget::itemFromIndex ( const QModelIndex index) const

Returns a pointer to the QTableWidgetItem associated with the given index.

Definition at line 2660 of file qtablewidget.cpp.

References d.

◆ itemPressed

void QTableWidget::itemPressed ( QTableWidgetItem item)
signal

This signal is emitted whenever an item in the table is pressed.

The item specified is the item that was pressed.

◆ itemPrototype()

const QTableWidgetItem * QTableWidget::itemPrototype ( ) const

Returns the item prototype used by the table.

See also
setItemPrototype()

Definition at line 2468 of file qtablewidget.cpp.

References d.

◆ items()

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 2636 of file qtablewidget.cpp.

References QTableWidgetMimeData::items.

◆ itemSelectionChanged

void QTableWidget::itemSelectionChanged ( )
signal

This signal is emitted whenever the selection changes.

See also
selectedItems(), QTableWidgetItem::isSelected()

◆ mimeData()

QMimeData * QTableWidget::mimeData ( const QList< QTableWidgetItem * > &  items) const
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 2577 of file qtablewidget.cpp.

References QList< T >::clear(), d, indexFromItem(), QList< T >::isEmpty(), item, items, QList< T >::reserve(), and QList< T >::size().

+ Here is the call graph for this function:

◆ mimeTypes()

QStringList QTableWidget::mimeTypes ( ) const
protectedvirtual

Returns a list of MIME types that can be used to describe a list of tablewidget items.

See also
mimeData()

Definition at line 2564 of file qtablewidget.cpp.

◆ openPersistentEditor()

void QTableWidget::openPersistentEditor ( QTableWidgetItem item)

Opens an editor for the give item.

The editor remains open after editing.

See also
closePersistentEditor(), isPersistentEditorOpen()

Definition at line 2249 of file qtablewidget.cpp.

References d, item, and QAbstractItemView::openPersistentEditor().

+ Here is the call graph for this function:

◆ removeCellWidget()

void QTableWidget::removeCellWidget ( int  row,
int  column 
)
inline
Since
4.3

Removes the widget set on the cell indicated by row and column.

Definition at line 327 of file qtablewidget.h.

References setCellWidget().

+ Here is the call graph for this function:

◆ removeColumn

void QTableWidget::removeColumn ( int  column)
slot

Removes the column column and all its items from the table.

Definition at line 2523 of file qtablewidget.cpp.

References d.

◆ removeRow

void QTableWidget::removeRow ( int  row)
slot

Removes the row row and all its items from the table.

Definition at line 2514 of file qtablewidget.cpp.

References d.

◆ row()

int QTableWidget::row ( const QTableWidgetItem item) const

Returns the row for the item.

Definition at line 1934 of file qtablewidget.cpp.

References d, and item.

◆ rowCount()

int QTableWidget::rowCount ( ) const

Returns the number of rows.

Definition at line 1902 of file qtablewidget.cpp.

References d.

◆ scrollToItem

void QTableWidget::scrollToItem ( const QTableWidgetItem item,
QAbstractItemView::ScrollHint  hint = EnsureVisible 
)
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 2453 of file qtablewidget.cpp.

References d, hint(), item, Q_ASSERT, and QTableView::scrollTo().

+ Here is the call graph for this function:

◆ selectedItems()

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.

See also
selectedIndexes()

Definition at line 2367 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().

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

◆ selectedRanges()

QList< QTableWidgetSelectionRange > QTableWidget::selectedRanges ( ) const

Returns a list of all selected ranges.

See also
QTableWidgetSelectionRange

Definition at line 2343 of file qtablewidget.cpp.

References i, QItemSelectionModel::selection, QAbstractItemView::selectionModel(), and QList< T >::size().

+ Here is the call graph for this function:

◆ setCellWidget()

void QTableWidget::setCellWidget ( int  row,
int  column,
QWidget widget 
)
Since
4.1

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.

...
setCellWidget(row, column, new QTextEdit);
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
void setCellWidget(int row, int column, QWidget *widget)
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
See also
cellWidget()

Definition at line 2315 of file qtablewidget.cpp.

References QAbstractItemModel::index(), QAbstractItemView::model(), QAbstractItemView::setIndexWidget(), and widget.

+ Here is the call graph for this function:

◆ setColumnCount()

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.

See also
setRowCount()

Definition at line 1915 of file qtablewidget.cpp.

References d.

◆ setCurrentCell() [1/2]

void QTableWidget::setCurrentCell ( int  row,
int  column 
)
Since
4.1

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.

See also
setCurrentItem(), currentRow(), currentColumn()

Definition at line 2187 of file qtablewidget.cpp.

References QAbstractItemView::model(), and QAbstractItemView::setCurrentIndex().

+ Here is the call graph for this function:

◆ setCurrentCell() [2/2]

void QTableWidget::setCurrentCell ( int  row,
int  column,
QItemSelectionModel::SelectionFlags  command 
)
Since
4.4

Sets the current cell to be the cell at position (row, column), using the given command.

See also
setCurrentItem(), currentRow(), currentColumn()

Definition at line 2200 of file qtablewidget.cpp.

References d, and QAbstractItemView::model().

+ Here is the call graph for this function:

◆ setCurrentItem() [1/2]

void QTableWidget::setCurrentItem ( QTableWidgetItem item)

Sets the current item to item.

Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, the item is also selected.

See also
currentItem(), setCurrentCell()

Definition at line 2157 of file qtablewidget.cpp.

References d, item, and QAbstractItemView::setCurrentIndex().

+ Here is the call graph for this function:

◆ setCurrentItem() [2/2]

void QTableWidget::setCurrentItem ( QTableWidgetItem item,
QItemSelectionModel::SelectionFlags  command 
)
Since
4.4

Sets the current item to be item, using the given command.

See also
currentItem(), setCurrentCell()

Definition at line 2170 of file qtablewidget.cpp.

References d, and item.

◆ setHorizontalHeaderItem()

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 2058 of file qtablewidget.cpp.

References d, item, and takeHorizontalHeaderItem().

Referenced by setHorizontalHeaderLabels().

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

◆ setHorizontalHeaderLabels()

void QTableWidget::setHorizontalHeaderLabels ( const QStringList labels)

Sets the horizontal header labels using labels.

Definition at line 2103 of file qtablewidget.cpp.

References QAbstractItemModel::columnCount(), d, i, item, QAbstractItemView::model(), and setHorizontalHeaderItem().

+ Here is the call graph for this function:

◆ setItem()

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

See also
item(), takeItem()

Definition at line 1980 of file qtablewidget.cpp.

References d, item, Q_UNLIKELY, qWarning, and takeItem().

Referenced by MainWindow::showTable().

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

◆ setItemPrototype()

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.

See also
itemPrototype()

Definition at line 2487 of file qtablewidget.cpp.

References d, and item.

◆ setModel()

void QTableWidget::setModel ( QAbstractItemModel model)
overrideprivatevirtual

Reimplemented from QTableView.

Definition at line 2669 of file qtablewidget.cpp.

References Q_ASSERT.

◆ setRangeSelected()

void QTableWidget::setRangeSelected ( const QTableWidgetSelectionRange range,
bool  select 
)

Selects or deselects the range depending on select.

Definition at line 2324 of file qtablewidget.cpp.

References QItemSelectionModel::Deselect, QAbstractItemModel::index(), QAbstractItemView::model(), QAbstractItemView::rootIndex(), QItemSelectionModel::Select, QItemSelectionModel::select(), select(), and QAbstractItemView::selectionModel().

+ Here is the call graph for this function:

◆ setRowCount()

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.

See also
setColumnCount()

Definition at line 1892 of file qtablewidget.cpp.

References d.

◆ setSortingEnabled()

void QTableWidget::setSortingEnabled ( bool  enable)

Definition at line 2219 of file qtablewidget.cpp.

References QTableView::setSortingEnabled().

+ Here is the call graph for this function:

◆ setVerticalHeaderItem()

void QTableWidget::setVerticalHeaderItem ( int  row,
QTableWidgetItem item 
)

Sets the vertical header item for row row to item.

Definition at line 2019 of file qtablewidget.cpp.

References d, item, and takeVerticalHeaderItem().

Referenced by setVerticalHeaderLabels().

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

◆ setVerticalHeaderLabels()

void QTableWidget::setVerticalHeaderLabels ( const QStringList labels)

Sets the vertical header labels using labels.

Definition at line 2085 of file qtablewidget.cpp.

References d, i, item, QAbstractItemView::model(), QAbstractItemModel::rowCount(), and setVerticalHeaderItem().

+ Here is the call graph for this function:

◆ sortItems()

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 2209 of file qtablewidget.cpp.

References d, QTableView::horizontalHeader(), and QHeaderView::setSortIndicator().

+ Here is the call graph for this function:

◆ supportedDropActions()

Qt::DropActions QTableWidget::supportedDropActions ( ) const
protectedvirtual

Returns the drop actions supported by this view.

See also
Qt::DropActions

Definition at line 2625 of file qtablewidget.cpp.

References Qt::MoveAction.

◆ takeHorizontalHeaderItem()

QTableWidgetItem * QTableWidget::takeHorizontalHeaderItem ( int  column)
Since
4.1 Removes the horizontal header item at column from the header without deleting it.

Definition at line 2073 of file qtablewidget.cpp.

References d.

Referenced by setHorizontalHeaderItem().

+ Here is the caller graph for this function:

◆ takeItem()

QTableWidgetItem * QTableWidget::takeItem ( int  row,
int  column 
)

Removes the item at row and column from the table without deleting it.

Definition at line 1998 of file qtablewidget.cpp.

References d, and item.

Referenced by setItem().

+ Here is the caller graph for this function:

◆ takeVerticalHeaderItem()

QTableWidgetItem * QTableWidget::takeVerticalHeaderItem ( int  row)
Since
4.1 Removes the vertical header item at row from the header without deleting it.

Definition at line 2034 of file qtablewidget.cpp.

References d.

Referenced by setVerticalHeaderItem().

+ Here is the caller graph for this function:

◆ verticalHeaderItem()

QTableWidgetItem * QTableWidget::verticalHeaderItem ( int  row) const

Returns the vertical header item for row row.

Definition at line 2010 of file qtablewidget.cpp.

References d.

◆ visualColumn()

int QTableWidget::visualColumn ( int  logicalColumn) const

Returns the visual column of the given logicalColumn.

Definition at line 2414 of file qtablewidget.cpp.

References QTableView::horizontalHeader(), and QHeaderView::visualIndex().

+ Here is the call graph for this function:

◆ visualItemRect()

QRect QTableWidget::visualItemRect ( const QTableWidgetItem item) const

Returns the rectangle on the viewport occupied by the item at item.

Definition at line 2437 of file qtablewidget.cpp.

References d, item, Q_ASSERT, and QTableView::visualRect().

+ Here is the call graph for this function:

◆ visualRow()

int QTableWidget::visualRow ( int  logicalRow) const

Returns the visual row of the given logicalRow.

Definition at line 2405 of file qtablewidget.cpp.

References QTableView::verticalHeader(), and QHeaderView::visualIndex().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QTableModel

friend class QTableModel
friend

Definition at line 198 of file qtablewidget.h.

Referenced by QTableWidget(), and QTableWidget().

Property Documentation

◆ columnCount

QTableWidget::columnCount
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 160 of file qtablewidget.h.

Referenced by findItems().

◆ rowCount

QTableWidget::rowCount
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 160 of file qtablewidget.h.


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