QTable(3qt)

๐Ÿ“ฆ version 3.3.8b, in fedora 43, fedora 44

๐ŸŒธ NAME ๐ŸŒธ

QTable โ€” flexible editable table widget โœจ (yeah this is the 3qt manual, iykyk ๐Ÿ’…)


๐Ÿ’– SYNOPSIS ๐Ÿ’–

#include <qtable.h>

Inherits QScrollView.

Inherited by QDataTable.

โœจ Public Members โœจ

  • QTable ( QWidget * parent = 0, const char * name = 0 )
  • QTable ( int numRows, int numCols, QWidget * parent = 0, const char * name = 0 )
  • ~QTable () โ€” the goodbye, bestie ๐Ÿซถ
  • QHeader * horizontalHeader () const
  • QHeader * verticalHeader () const
  • enum SelectionMode { Single, Multi, SingleRow, MultiRow, NoSelection }
  • virtual void setSelectionMode ( SelectionMode mode )
  • SelectionMode selectionMode () const
  • virtual void setItem ( int row, int col, QTableItem * item )
  • virtual void setText ( int row, int col, const QString & text )
  • virtual void setPixmap ( int row, int col, const QPixmap & pix )
  • virtual QTableItem * item ( int row, int col ) const
  • virtual QString text ( int row, int col ) const
  • virtual QPixmap pixmap ( int row, int col ) const
  • virtual void clearCell ( int row, int col )
  • virtual QRect cellGeometry ( int row, int col ) const
  • virtual int columnWidth ( int col ) const
  • virtual int rowHeight ( int row ) const
  • virtual int columnPos ( int col ) const
  • virtual int rowPos ( int row ) const
  • virtual int columnAt ( int x ) const
  • virtual int rowAt ( int y ) const
  • virtual int numRows () const
  • virtual int numCols () const
  • void updateCell ( int row, int col )
  • int currentRow () const
  • int currentColumn () const
  • void ensureCellVisible ( int row, int col )
  • bool isSelected ( int row, int col ) const
  • bool isRowSelected ( int row, bool full = FALSE ) const
  • bool isColumnSelected ( int col, bool full = FALSE ) const
  • int numSelections () const
  • QTableSelection selection ( int num ) const
  • virtual int addSelection ( const QTableSelection & s )
  • virtual void removeSelection ( const QTableSelection & s )
  • virtual void removeSelection ( int num )
  • virtual int currentSelection () const
  • void selectCells ( int start_row, int start_col, int end_row, int end_col )
  • void selectRow ( int row )
  • void selectColumn ( int col )
  • bool showGrid () const
  • bool columnMovingEnabled () const
  • bool rowMovingEnabled () const
  • virtual void sortColumn ( int col, bool ascending = TRUE, bool wholeRows = FALSE )
  • bool sorting () const
  • virtual void takeItem ( QTableItem * i )
  • virtual void setCellWidget ( int row, int col, QWidget * e )
  • virtual QWidget * cellWidget ( int row, int col ) const
  • virtual void clearCellWidget ( int row, int col )
  • virtual QRect cellRect ( int row, int col ) const
  • virtual void paintCell ( QPainter * p, int row, int col, const QRect & cr, bool selected )
  • virtual void paintCell ( QPainter * p, int row, int col, const QRect & cr, bool selected, const QColorGroup & cg )
  • virtual void paintFocus ( QPainter * p, const QRect & cr )
  • bool isReadOnly () const
  • bool isRowReadOnly ( int row ) const
  • bool isColumnReadOnly ( int col ) const
  • void repaintSelections ()
  • enum FocusStyle { FollowStyle, SpreadSheet }
  • virtual void setFocusStyle ( FocusStyle fs )
  • FocusStyle focusStyle () const
  • void updateHeaderStates ()

๐ŸŽ€ Public Slots ๐ŸŽ€

  • virtual void setNumRows ( int r )
  • virtual void setNumCols ( int r )
  • virtual void setShowGrid ( bool b )
  • virtual void hideRow ( int row )
  • virtual void hideColumn ( int col )
  • virtual void showRow ( int row )
  • virtual void showColumn ( int col )
  • bool isRowHidden ( int row ) const
  • bool isColumnHidden ( int col ) const
  • virtual void setColumnWidth ( int col, int w )
  • virtual void setRowHeight ( int row, int h )
  • virtual void adjustColumn ( int col )
  • virtual void adjustRow ( int row )
  • virtual void setColumnStretchable ( int col, bool stretch )
  • virtual void setRowStretchable ( int row, bool stretch )
  • bool isColumnStretchable ( int col ) const
  • bool isRowStretchable ( int row ) const
  • virtual void setSorting ( bool b )
  • virtual void swapRows ( int row1, int row2, bool swapHeader = FALSE )
  • virtual void swapColumns ( int col1, int col2, bool swapHeader = FALSE )
  • virtual void swapCells ( int row1, int col1, int row2, int col2 )
  • virtual void setLeftMargin ( int m )
  • virtual void setTopMargin ( int m )
  • virtual void setCurrentCell ( int row, int col )
  • void clearSelection ( bool repaint = TRUE )
  • virtual void setColumnMovingEnabled ( bool b )
  • virtual void setRowMovingEnabled ( bool b )
  • virtual void setReadOnly ( bool b )
  • virtual void setRowReadOnly ( int row, bool ro )
  • virtual void setColumnReadOnly ( int col, bool ro )
  • virtual void setDragEnabled ( bool b )
  • bool dragEnabled () const
  • virtual void insertRows ( int row, int count = 1 )
  • virtual void insertColumns ( int col, int count = 1 )
  • virtual void removeRow ( int row )
  • virtual void removeRows ( const QMemArray<int> & rows )
  • virtual void removeColumn ( int col )
  • virtual void removeColumns ( const QMemArray<int> & cols )
  • virtual void editCell ( int row, int col, bool replace = FALSE )
  • void setRowLabels ( const QStringList & labels )
  • void setColumnLabels ( const QStringList & labels )

๐Ÿฆ‹ Signals ๐Ÿฆ‹

  • void currentChanged ( int row, int col )
  • void clicked ( int row, int col, int button, const QPoint & mousePos )
  • void doubleClicked ( int row, int col, int button, const QPoint & mousePos )
  • void pressed ( int row, int col, int button, const QPoint & mousePos )
  • void selectionChanged ()
  • void valueChanged ( int row, int col )
  • void contextMenuRequested ( int row, int col, const QPoint & pos )
  • void dropped ( QDropEvent * e )

๐ŸŒˆ Properties ๐ŸŒˆ

  • bool columnMovingEnabled โ€” whether columns can be moved by the user
  • FocusStyle focusStyle โ€” how the current (focus) cell is drawn
  • int numCols โ€” the number of columns in the table
  • int numRows โ€” the number of rows in the table
  • int numSelections โ€” the number of selections (read only ๐Ÿ‘€)
  • bool readOnly โ€” whether the table is read-only
  • bool rowMovingEnabled โ€” whether rows can be moved by the user
  • SelectionMode selectionMode โ€” the current selection mode
  • bool showGrid โ€” whether the table's grid is displayed
  • bool sorting โ€” whether a click on the header of a column sorts that column

๐Ÿ’œ Protected Members ๐Ÿ’œ

  • enum EditMode { NotEditing, Editing, Replacing }
  • virtual void drawContents ( QPainter * p, int cx, int cy, int cw, int ch )
  • void setEditMode ( EditMode mode, int row, int col )
  • virtual void contentsDragEnterEvent ( QDragEnterEvent * e )
  • virtual void contentsDragMoveEvent ( QDragMoveEvent * e )
  • virtual void contentsDragLeaveEvent ( QDragLeaveEvent * e )
  • virtual void contentsDropEvent ( QDropEvent * e )
  • virtual QDragObject * dragObject ()
  • virtual void startDrag ()
  • virtual void paintEmptyArea ( QPainter * p, int cx, int cy, int cw, int ch )
  • virtual void activateNextCell ()
  • virtual QWidget * createEditor ( int row, int col, bool initFromCell ) const
  • virtual void setCellContentFromEditor ( int row, int col )
  • virtual QWidget * beginEdit ( int row, int col, bool replace )
  • virtual void endEdit ( int row, int col, bool accept, bool replace )
  • virtual void resizeData ( int len )
  • virtual void insertWidget ( int row, int col, QWidget * w )
  • int indexOf ( int row, int col ) const
  • bool isEditing () const
  • EditMode editMode () const
  • int currEditRow () const
  • int currEditCol () const

๐Ÿงš Protected Slots ๐Ÿงš

  • virtual void columnWidthChanged ( int col )
  • virtual void rowHeightChanged ( int row )
  • virtual void columnIndexChanged ( int section, int fromIndex, int toIndex )
  • virtual void rowIndexChanged ( int section, int fromIndex, int toIndex )
  • virtual void columnClicked ( int col )

๐Ÿ’… DESCRIPTION ๐Ÿ’…

okay so. The QTable class provides a flexible editable table widget. That's the whole vibe, bestie. ๐Ÿ’–

QTable is easy to use, although it does have a large API because of the comprehensive functionality that it provides. Like, it's not bloated, it's thorough. ๐Ÿ‘‘

QTable includes functions for manipulating:

  • headers
  • rows and columns
  • cells and selections

QTable also provides in-place editing and drag and drop, as well as a useful set of signals. ๐Ÿ”ฅ

QTable efficiently supports very large tables โ€” for example, tables one million by one million cells are perfectly possible. No cap. And QTable is economical with memory, using none for unused cells. The way it's just sitting there using zero memory for cells you never touched? Iconic. โœจ

QTable *table = new QTable( 100, 250, this );
table->setPixmap( 3, 2, pix );
table->setText( 3, 2, "A pixmap" );

So the first line constructs the table specifying its size in rows and columns. Then we insert a pixmap and some text into the same cell, with the pixmap appearing to the left of the text. Cute, right? ๐ŸŽ€

QTable cells can be populated with QTableItems, QComboTableItems or by QCheckTableItems. By default a vertical header appears at the left of the table showing row numbers and a horizontal header appears at the top of the table showing column numbers. And heads up โ€” the numbers displayed start at 1, even though row and column numbers within QTable begin at 0. Yes, that's a thing. ๐Ÿ™ˆ

If you want to use mouse tracking call setMouseTracking( TRUE ) on the viewport; (see QScrollView). ๐Ÿ–ฑ๏ธ

(There was an image here in the original โ€” picture a table widget looking absolutely stunning. โœจ [Image Omitted])

๐ŸŒธ Headers ๐ŸŒธ

QTable supports a header column, e.g. to display row numbers, and a header row, e.g to display column titles. ๐Ÿ’…

To set row or column labels use QHeader::setLabel() on the pointers returned by verticalHeader() and horizontalHeader() respectively.

  • The vertical header is displayed within the table's left margin whose width is set with setLeftMargin().
  • The horizontal header is displayed within the table's top margin whose height is set with setTopMargin().

The table's grid can be switched off with setShowGrid().

If you want to hide a horizontal header call hide(), and call setTopMargin( 0 ) so that the area the header would have occupied is reduced to zero size. Poof, gone. ๐Ÿซฅ

Header labels are indexed via their section numbers. Note that the default behavior of QHeader regarding section numbers is overriden for QTable. See the explanation below in the Rows and Columns section in the discussion of moving columns and rows. ๐Ÿ‘€

Rows and Columns ๐Ÿ‘‘

okay bestie, so row and column sizes? You set them with setRowHeight() and setColumnWidth(). Want a row tall enough to show the tallest item all the way? Use adjustRow(). Same energy for a column that should fit the widest item: adjustColumn(). And if you want row height and column width to auto-adjust as the table's height/width changes? setRowStretchable() and setColumnStretchable() are your girls. โœจ slay โœจ

Rows and columns can be hidden and shown with hideRow(), hideColumn(), showRow() and showColumn(). New rows and columns? Insert them with insertRows() and insertColumns(). Extra rows and columns get added at the bottom (rows) or right (columns) if you set setNumRows() or setNumCols() larger than numRows() or numCols(). Existing ones get removed with removeRow() and removeColumn(). Multiple at once? removeRows() and removeColumns(). ๐Ÿ’… periodt

Rows and columns can be set to be moveable using rowMovingEnabled() and columnMovingEnabled(). The user can drag them to reorder them holding down the Ctrl key and dragging the mouse. For performance reasons, the default behavior of QHeader section numbers is overridden by QTable. Currently in QTable, when a row or column is dragged and reordered, the section number is also changed to its new position. Therefore, there is no difference between the section and the index fields in QHeader. The QTable QHeader classes do not provide a mechanism for indexing independently of the user interface ordering. (not me explaining QHeader lore but go off) ๐Ÿ˜ญ

The table can be sorted using sortColumn(). Users can sort a column by clicking its header if setSorting() is set to TRUE. Rows can be swapped with swapRows(), columns with swapColumns() and cells with swapCells(). ๐Ÿ”ฅ iconic

For editable tables (see setReadOnly()) you can set the read-only property of individual rows and columns with setRowReadOnly() and setColumnReadOnly(). (Whether a cell is editable or read-only depends on these settings and the cell's QTableItem::EditType.) ๐ŸŽ€

The row and column which have the focus are returned by currentRow() and currentColumn() respectively. ๐Ÿ‘‘ main character energy

Although many QTable functions operate in terms of rows and columns the indexOf() function returns a single integer identifying a particular cell. iykyk ๐Ÿ’–


Cells ๐Ÿงš

All of a QTable's cells are empty when the table is constructed. Blank slate, main character energy. โœจ

There are two approaches to populating the table's cells. The first and simplest approach is to use QTableItems or QTableItem subclasses. The second approach doesn't use QTableItems at all which is useful for very large sparse tables but requires you to reimplement a number of functions. We'll look at each approach in turn. ๐Ÿ‘€

To put a string in a cell use setText(). This function will create a new QTableItem for the cell if one doesn't already exist, and displays the text in it. By default the table item's widget will be a QLineEdit. A pixmap may be put in a cell with setPixmap(), which also creates a table item if required. A cell may contain both a pixmap and text; the pixmap is displayed to the left of the text. Another approach is to construct a QTableItem or QTableItem subclass, set its properties, then insert it into a cell with setItem(). ๐Ÿ’…

If you want cells which contain comboboxes use the QComboTableItem class. Similarly if you require cells containing checkboxes use the QCheckTableItem class. These table items look and behave just like the combobox or checkbox widgets but consume far less memory. Slay, memory efficiency. ๐Ÿ”ฅ

for ( int j = 0; j < numRows; ++j )
    table.setItem( j, 1, new QCheckTableItem( &table, "Check me" ) );

In the example above we create a column of QCheckTableItems and insert them into the table using setItem(). โœจ

QTable takes ownership of its QTableItems and will delete them when the table itself is destroyed. You can take ownership of a table item using takeItem() which you use to move a cell's contents from one cell to another, either within the same table, or from one table to another. (See also, swapCells()). ๐Ÿซถ

In-place editing of the text in QTableItems, and the values in QComboTableItems and QCheckTableItems works automatically. Cells may be editable or read-only, see QTableItem::EditType. If you want fine control over editing see beginEdit() and endEdit(). ๐Ÿ˜Œ

The contents of a cell can be retrieved as a QTableItem using item(), or as a string with text() or as a pixmap (if there is one) with pixmap(). A cell's bounding rectangle is given by cellGeometry(). Use updateCell() to repaint a cell, for example to clear away a cell's visual representation after it has been deleted with clearCell(). The table can be forced to scroll to show a particular cell with ensureCellVisible(). The isSelected() function indicates if a cell is selected. ๐Ÿ’–

It is possible to use your own widget as a cell's widget using setCellWidget(), but subclassing QTableItem might be a simpler approach. The cell's widget (if there is one) can be removed with clearCellWidget(). ๐ŸŽ€

Large tables ๐Ÿ‘‘

For large, sparse, tables using QTableItems or other widgets is inefficient. The solution is to draw the cell as it should appear and to create and destroy cell editors on demand. Lowkey iconic. โœจ

This approach requires that you reimplement various functions. Reimplement paintCell() to display your data, and createEditor() and setCellContentFromEditor() to support in-place editing. It is very important to reimplement resizeData() to have no functionality, to prevent QTable from attempting to create a huge array. You will also need to reimplement item(), setItem(), takeItem(), clearCell(), and insertWidget(), cellWidget() and clearCellWidget(). In almost every circumstance (for sorting, removing and inserting columns and rows, etc.), you also need to reimplement swapRows(), swapCells() and swapColumns(), including header handling. ๐Ÿ˜ญ

If you represent active cells with a dictionary of QTableItems and QWidgets, i.e. only store references to cells that are actually used, many of the functions can be implemented with a single line of code. (See the table/bigtable/main.cpp example.) ๐Ÿ”ฅ

For more information on cells see the QTableItem documenation. ๐Ÿ’…


Selections ๐Ÿ’œ

QTable's support single selection, multi-selection (multiple cells) or no selection. The selection mode is set with setSelectionMode(). Use isSelected() to determine if a particular cell is selected, and isRowSelected() and isColumnSelected() to see if a row or column is selected. ๐Ÿ‘‘

QTable's support many simultaneous selections. You can programmatically select cells with addSelection(). The number of selections is given by numSelections(). The current selection is returned by currentSelection(). You can remove a selection with removeSelection() and remove all selections with clearSelection(). Selections are QTableSelection objects. ๐Ÿซถ

To easily add a new selection use selectCells(), selectRow() or selectColumn(). โœจ

Alternatively, use addSelection() to add new selections using QTableSelection objects. The advantage of using QTableSelection objects is that you can call QTableSelection::expandTo() to resize the selection and can query and compare them. ๐Ÿ’–

The number of selections is given by numSelections(). The current selection is returned by currentSelection(). You can remove a selection with removeSelection() and remove all selections with clearSelection(). (Yes she repeated herself, and? It's important.) ๐Ÿ˜Œ


Signals ๐Ÿ“ฃ

When the user clicks a cell the currentChanged() signal is emitted. You can also connect to the lower level clicked(), doubleClicked() and pressed() signals. If the user changes the selection the selectionChanged() signal is emitted; similarly if the user changes a cell's value the valueChanged() signal is emitted. If the user right-clicks (or presses the appropriate platform-specific key sequence) the contextMenuRequested() signal is emitted. If the user drops a drag and drop object the dropped() signal is emitted with the drop event. ๐ŸŽ€

See also Advanced Widgets.


โœจ Member Type Documentation โœจ

QTable::EditMode

  • QTable::NotEditing โ€” No cell is currently being edited.
  • QTable::Editing โ€” A cell is currently being edited. The editor was initialised with the cell's contents.
  • QTable::Replacing โ€” A cell is currently being edited. The editor was not initialised with the cell's contents.

QTable::FocusStyle

Specifies how the current cell (focus cell) is drawn. ๐Ÿ‘‘

  • QTable::FollowStyle โ€” The current cell is drawn according to the current style and the cell's background is also drawn selected, if the current cell is within a selection
  • QTable::SpreadSheet โ€” The current cell is drawn as in a spreadsheet. This means, it is signified by a black rectangle around the cell, and the background of the current cell is always drawn with the widget's base color - even when selected.

QTable::SelectionMode

  • QTable::NoSelection โ€” No cell can be selected by the user.
  • QTable::Single โ€” The user may only select a single range of cells.
  • QTable::Multi โ€” The user may select multiple ranges of cells.
  • QTable::SingleRow โ€” The user may select one row at once.
  • QTable::MultiRow โ€” The user may select multiple rows.

๐Ÿ’… MEMBER FUNCTION DOCUMENTATION ๐Ÿ’…

QTable::QTable ( QWidget * parent = 0, const char * name = 0 )

Creates an empty table object called name as a child of parent. โœจ

Call setNumRows() and setNumCols() to set the table size before populating the table if you're using QTableItems. ๐Ÿซถ

See also QWidget::clearWFlags() and Qt::WidgetFlags.

QTable::QTable ( int numRows, int numCols, QWidget * parent = 0, const char * name = 0 )

Constructs an empty table called name with numRows rows and numCols columns. The table is a child of parent. ๐Ÿ’–

If you're using QTableItems to populate the table's cells, you can create QTableItem, QComboTableItem and QCheckTableItem items and insert them into the table using setItem(). (See the notes on large tables for an alternative to using QTableItems.) ๐Ÿ‘‘

See also QWidget::clearWFlags() and Qt::WidgetFlags.

QTable::~QTable ()

Releases all the resources used by the QTable object, including all QTableItems and their widgets. ๐Ÿ˜ญ bye bestie.

void QTable::activateNextCell () [virtual protected]

This function is called to activate the next cell if in-place editing was finished by pressing the Enter key. โŒจ๏ธ

The default behaviour is to move from top to bottom, i.e. move to the cell beneath the cell being edited. Reimplement this function if you want different behaviour, e.g. moving from left to right. ๐Ÿ’…

int QTable::addSelection ( const QTableSelection & s ) [virtual]

Adds a selection described by s to the table and returns its number or -1 if the selection is invalid. ๐Ÿ”ฅ

Remember to call QTableSelection::init() and QTableSelection::expandTo() to make the selection valid (see also QTableSelection::isActive(), or use the QTableSelection(int,int,int,int) constructor). โœจ

See also numSelections, removeSelection(), and clearSelection().

๐Ÿงต void QTable::adjustColumn ( int col ) [virtual slot]

Resizes column col so that the column width is wide enough to display the widest item the column contains. Basically it does a vibe check on the whole column and stretches it until nothing is getting cut off. โœจ

See also adjustRow().

Example: regexptester/regexptester.cpp.

Reimplemented in QDataTable.


๐Ÿ“ void QTable::adjustRow ( int row ) [virtual slot]

Resizes row row so that the row height is tall enough to display the tallest item the row contains. No more squished cells, bestie, the row gets the space it needs. ๐Ÿ’…

See also adjustColumn().


โœ๏ธ QWidget * QTable::beginEdit ( int row, int col, bool replace ) [virtual protected]

This function is called to start in-place editing of the cell at row, col. Editing is achieved by creating an editor (createEditor() is called) and setting the cell's editor with setCellWidget() to the newly created editor. (After editing is complete endEdit() will be called to replace the cell's content with the editor's content.)

If replace is TRUE the editor will start empty; otherwise it will be initialized with the cell's content (if any), i.e. the user will be modifying the original cell content. So like โ€” blank slate vs. editing what's already there. ๐Ÿ‘‘

See also endEdit().


๐Ÿ—บ๏ธ QRect QTable::cellGeometry ( int row, int col ) const [virtual]

Returns the bounding rectangle of the cell at row, col in content coordinates. That's the cell's whole little house in the table's coordinate system, fr fr. ๐Ÿ 


๐Ÿ“ QRect QTable::cellRect ( int row, int col ) const [virtual]

Returns the geometry of cell row, col in the cell's coordinate system. This is a convenience function useful in paintCell(). It is equivalent to:

QRect( QPoint(0,0), cellGeometry( row, col).size() );

So it's the same size as the cell geometry, but anchored at the origin instead of out in content-coordinate land.

See also cellGeometry().

Example: chart/setdataform.cpp.


๐ŸŽ QWidget * QTable::cellWidget ( int row, int col ) const [virtual]

Returns the widget that has been set for the cell at row, col, or 0 if no widget has been set. Surprise widget? Nope, 0, nothing there. ๐Ÿ™ˆ

If you don't use QTableItems you may need to reimplement this function: see the notes on large tables.

See also clearCellWidget() and setCellWidget().

Example: chart/setdataform.cpp.


๐Ÿงน void QTable::clearCell ( int row, int col ) [virtual]

Removes the QTableItem at row, col. Poof, gone, no item left. ๐Ÿ’จ

If you don't use QTableItems you may need to reimplement this function: see the notes on large tables.


๐Ÿซง void QTable::clearCellWidget ( int row, int col ) [virtual]

Removes the widget (if there is one) set for the cell at row, col.

If you don't use QTableItems you may need to reimplement this function: see the notes on large tables.

This function deletes the widget at row, col. Note that the widget is not deleted immediately; instead QObject::deleteLater() is called on the widget to avoid problems with timing issues. So it's not ghosting you, it's just scheduling the breakup. ๐Ÿ˜ญ

See also cellWidget() and setCellWidget().


๐Ÿงฝ void QTable::clearSelection ( bool repaint = TRUE ) [slot]

Clears all selections and repaints the appropriate regions if repaint is TRUE. Everything unselected, clean slate energy. โœจ

See also removeSelection().


๐Ÿ–ฑ๏ธ void QTable::clicked ( int row, int col, int button, const QPoint & mousePos ) [signal]

This signal is emitted when mouse button button is clicked. The cell where the event took place is at row, col, and the mouse's position is in mousePos. The click heard round the table. ๐Ÿ”ฅ

See also Qt::ButtonState.

Example: chart/setdataform.cpp.


๐Ÿงญ int QTable::columnAt ( int x ) const [virtual]

Returns the number of the column at position x. x must be given in content coordinates. So like, "which column lives at this x spot?" โ€” this function knows. ๐Ÿ’ซ

See also columnPos() and rowAt().


๐Ÿ‘† void QTable::columnClicked ( int col ) [virtual protected slot]

This function is called when the column col has been clicked. The default implementation sorts this column if sorting() is TRUE. Iconic default behaviour, honestly. ๐Ÿ‘‘


๐Ÿ”€ void QTable::columnIndexChanged ( int section, int fromIndex, int toIndex ) [virtual protected slot]

This function is called when column order is to be changed, i.e. when the user moved the column header section from fromIndex to toIndex.

If you want to change the column order programmatically, call swapRows() or swapColumns(); โ€” yes bestie, that semicolon is literally in the original, we keep it. ๐ŸŽ€

See also QHeader::indexChange() and rowIndexChanged().


๐Ÿšš bool QTable::columnMovingEnabled () const

Returns TRUE if columns can be moved by the user; otherwise returns FALSE. See the "columnMovingEnabled" property for details.


๐Ÿ“ int QTable::columnPos ( int col ) const [virtual]

Returns the x-coordinate of the column col in content coordinates. Column position, pinpointed. ๐ŸŒธ

See also columnAt() and rowPos().


โ†”๏ธ int QTable::columnWidth ( int col ) const [virtual]

Returns the width of column col. How wide is she? This tells you. ๐Ÿ’…

See also setColumnWidth() and rowHeight().


๐Ÿ“ข void QTable::columnWidthChanged ( int col ) [virtual protected slot]

This function should be called whenever the column width of col has been changed. It updates the geometry of any affected columns and repaints the table to reflect the changes it has made. Like a lil group announcement that things moved. โœจ


๐Ÿช‚ void QTable::contentsDragEnterEvent ( QDragEnterEvent * e ) [virtual protected]

This event handler is called whenever a QTable object receives a QDragEnterEvent e, i.e. when the user pressed the mouse button to drag something.

The focus is moved to the cell where the QDragEnterEvent occurred.

Reimplemented from QScrollView.


๐Ÿซฅ void QTable::contentsDragLeaveEvent ( QDragLeaveEvent * e ) [virtual protected]

This event handler is called when a drag activity leaves this QTable object with event e. Bye drag, we hardly knew ye. ๐Ÿ‘‹

Reimplemented from QScrollView.


๐Ÿ› void QTable::contentsDragMoveEvent ( QDragMoveEvent * e ) [virtual protected]

This event handler is called whenever a QTable object receives a QDragMoveEvent e, i.e. when the user actually drags the mouse.

The focus is moved to the cell where the QDragMoveEvent occurred.

Reimplemented from QScrollView.


๐Ÿ’ง void QTable::contentsDropEvent ( QDropEvent * e ) [virtual protected]

This event handler is called when the user ends a drag and drop by dropping something onto this QTable and thus triggers the drop event, e. The moment of release, the drop, the slay. ๐ŸŽ€

Reimplemented from QScrollView.


๐Ÿฅž void QTable::contextMenuRequested ( int row, int col, const QPoint & pos ) [signal]

This signal is emitted when the user invokes a context menu with the right mouse button (or with a system-specific keypress). The cell where the event took place is at row, col. pos is the position where the context menu will appear in the global coordinate system. This signal is always emitted, even if the contents of the cell are disabled. Yeah, even then. No skipping. ๐Ÿซถ


๐Ÿ› ๏ธ QWidget * QTable::createEditor ( int row, int col, bool initFromCell ) const [virtual protected]

This function returns the widget which should be used as an editor for the contents of the cell at row, col.

If initFromCell is TRUE, the editor is used to edit the current contents of the cell (so the editor widget should be initialized with this content). If initFromCell is FALSE, the content of the cell is replaced with the new content which the user entered into the widget created by this function.

The default functionality is as follows: if initFromCell is TRUE or the cell has a QTableItem and the table item's QTableItem::isReplaceable() is FALSE then the cell is asked to create an appropriate editor (using QTableItem::createEditor()). Otherwise a QLineEdit is used as the editor.

If you want to create your own editor for certain cells, implement a custom QTableItem subclass and reimplement QTableItem::createEditor().

If you are not using QTableItems and you don't want to use a QLineEdit as the default editor, subclass QTable and reimplement this function with code like this:

    QTableItem *i = item( row, col );
    if ( initFromCell || ( i && !i->isReplaceable() ) )
        // If we had a QTableItem ask the base class to create the editor
        return QTable::createEditor( row, col, initFromCell );
    else
        return ...(create your own editor)

Ownership of the editor widget is transferred to the caller.

If you reimplement this function return 0 for read-only cells. You will need to reimplement setCellContentFromEditor() to retrieve the data the user entered.

See also QTableItem::createEditor().


๐Ÿงฎ int QTable::currEditCol () const [protected]

Returns the current edited column


๐Ÿงฎ int QTable::currEditRow () const [protected]

Returns the current edited row


๐ŸŒŸ void QTable::currentChanged ( int row, int col ) [signal]

This signal is emitted when the current cell has changed to row, col. New main character cell just dropped. ๐Ÿ‘‘

Example: chart/setdataform.cpp.


๐Ÿงท int QTable::currentColumn () const

Returns the current column.

See also currentRow().

Example: chart/setdataform.cpp.


๐Ÿงท int QTable::currentRow () const

Returns the current row.

See also currentColumn().

Example: chart/setdataform.cpp.


๐Ÿ”Ž int QTable::currentSelection () const [virtual]

Returns the number of the current selection or -1 if there is no current selection. (-1 is giving "nobody's home" energy. ๐Ÿ’€)

See also numSelections.


๐Ÿ‘†๐Ÿ‘† void QTable::doubleClicked ( int row, int col, int button, const QPoint & mousePos ) [signal]

This signal is emitted when mouse button button is double-clicked. The cell where the event took place is at row, col, and the mouse's position is in mousePos. Double tap, double slay. โœจ

See also Qt::ButtonState.


๐ŸŽˆ bool QTable::dragEnabled () const [slot]

If this function returns TRUE, the table supports dragging.

See also setDragEnabled().


๐Ÿ‰ QDragObject * QTable::dragObject () [virtual protected]

If the user presses the mouse on a selected cell, starts moving (i.e. dragging), and dragEnabled() is TRUE, this function is called to obtain a drag object. A drag using this object begins immediately unless dragObject() returns 0.

By default this function returns 0. You might reimplement it and create a QDragObject depending on the selected items.

See also dropped().


๐ŸŽจ void QTable::drawContents ( QPainter * p, int cx, int cy, int cw, int ch ) [virtual protected]

Draws the table contents on the painter p. This function is optimized so that it only draws the cells inside the cw pixels wide and ch pixels high clipping rectangle at position cx, cy.

Additionally, drawContents() highlights the current cell.

Reimplemented from QScrollView.


๐Ÿช„ void QTable::dropped ( QDropEvent * e ) [signal]

This signal is emitted when a drop event occurred on the table.

e contains information about the drop.


๐Ÿ“ void QTable::editCell ( int row, int col, bool replace = FALSE ) [virtual slot]

Starts editing the cell at row, col.

If replace is TRUE the content of this cell will be replaced by the content of the editor when editing is finished, i.e. the user will be entering new data; otherwise the current content of the cell (if any) will be modified in the editor. Fresh data or edited data, your call bestie. ๐ŸŽ€

See also beginEdit().


๐ŸŽ›๏ธ EditMode QTable::editMode () const [protected]

Returns the current edit mode

See also QTable::EditMode.


void QTable::endEdit ( int row, int col, bool accept, bool replace ) [virtual protected]

Ok bestie, this one fires the moment somebody asks for in-place editing of the cell at row, col to stop. Editing era over ๐Ÿ’…

So here's the tea on how it decides stuff:

  • If the cell isn't even being edited, or accept is FALSE โ€” the function just returns and the cell's contents stay exactly as they were. Nothing happens, no drama. ๐Ÿ™ˆ
  • If accept is TRUE, then the content of the editor must be transferred to the relevant cell. And here's the nuance: if replace is TRUE, the current content of this cell should be replaced by the content of the editor โ€” which means removing the current QTableItem of the cell and creating a brand new one for the cell. Otherwise (if it's possible, anyway) the content of the editor should just be set to the existing QTableItem of this cell. ๐Ÿ‘‘

Then setCellContentFromEditor() gets called to replace the contents of the cell with the contents of the cell's editor. โœจ

And finally clearCellWidget() is called to remove the editor widget. Byeee widget ๐Ÿซถ

See also setCellContentFromEditor() and beginEdit().


void QTable::ensureCellVisible ( int row, int col )

Scrolls the table until the cell at row, col becomes visible. It's giving "we will find you and we will scroll to you" ๐Ÿ”โœจ


FocusStyle QTable::focusStyle () const

Returns how the current (focus) cell is drawn. Peep the "focusStyle" property for all the deets. ๐ŸŽ€


void QTable::hideColumn ( int col ) [virtual slot]

Hides column col. Poof, gone, ghosted ๐Ÿ‘ป

See also showColumn() and hideRow().


void QTable::hideRow ( int row ) [virtual slot]

Hides row row. Same energy, different axis. ๐Ÿ’€

See also showRow() and hideColumn().


QHeader * QTable::horizontalHeader () const

Returns the table's top QHeader. This header is where the column labels live, bestie โ€” it's the main character of your table's top edge ๐Ÿ‘‘

Wanna change a column label? Use QHeader::setLabel(), like so:

horizontalHeader()->setLabel( 0, tr( "File" ) );

See also verticalHeader(), setTopMargin(), and QHeader.

Examples: (the original page references examples here) ๐ŸŒธ


int QTable::indexOf ( int row, int col ) const [protected]

Returns a single integer that identifies a particular row and col by mapping the 2D table to a 1D array. Math but make it slay ๐Ÿงฎโœจ

This is lowkey useful, for example, if you've got a sparse table and you wanna use a QIntDict to map integers to the cells that are actually in use. iykyk ๐Ÿ’…


void QTable::insertColumns ( int col, int count = 1 ) [virtual slot]

Inserts count empty columns at column col. Also clears the selection(s). Fresh columns, who dis ๐ŸŒฑ

See also insertRows() and removeColumn().


void QTable::insertRows ( int row, int count = 1 ) [virtual slot]

Inserts count empty rows at row row. Also clears the selection(s). New row smell ๐Ÿฆ‹

See also insertColumns() and removeRow().


void QTable::insertWidget ( int row, int col, QWidget * w ) [virtual protected]

Inserts widget w at row, col into the internal data structure. Go read the setCellWidget() docs for the full lore on this one. ๐Ÿ“š

Heads up: if you don't use QTableItems, you may need to reimplement this function โ€” see the notes on large tables. ๐Ÿ‘€

bool QTable::isColumnHidden ( int col ) const [slot]

Returns TRUE if column col is hidden; otherwise returns FALSE. Vibe check on the column's visibility ๐Ÿ•ต๏ธโ€โ™€๏ธ

See also hideColumn() and isRowHidden().


bool QTable::isColumnReadOnly ( int col ) const

Returns TRUE if column col is read-only; otherwise returns FALSE.

Whether a cell in this column is editable or read-only depends on the cell's EditType, and this setting: see QTableItem::EditType. Two things gotta agree, it's a whole collab ๐Ÿค

See also setColumnReadOnly() and isRowReadOnly().


bool QTable::isColumnSelected ( int col, bool full = FALSE ) const

Returns TRUE if column col is selected; otherwise returns FALSE.

Here's the distinction, don't skip it bestie:

  • If full is FALSE (the default), "column is selected" means that at least one cell in the column is selected.
  • If full is TRUE, then "column is selected" means every cell in the column is selected.

See also isRowSelected() and isSelected().


bool QTable::isColumnStretchable ( int col ) const [slot]

Returns TRUE if column col is stretchable; otherwise returns FALSE. Get that column its yoga mat ๐Ÿง˜โ€โ™€๏ธ

See also setColumnStretchable() and isRowStretchable().


bool QTable::isEditing () const [protected]

Returns TRUE if the EditMode is Editing or Replacing; otherwise (i.e. the EditMode is NotEditing) returns FALSE. So it's basically asking "are we in our editing era rn?" ๐Ÿ“

See also QTable::EditMode.


bool QTable::isReadOnly () const

Returns TRUE if the table is read-only; otherwise returns FALSE. See the "readOnly" property for details. Look don't touch, respectfully ๐Ÿ™…โ€โ™€๏ธ


bool QTable::isRowHidden ( int row ) const [slot]

Returns TRUE if row row is hidden; otherwise returns FALSE.

See also hideRow() and isColumnHidden().


bool QTable::isRowReadOnly ( int row ) const

Returns TRUE if row row is read-only; otherwise returns FALSE.

Whether a cell in this row is editable or read-only depends on the cell's EditType, and this setting: see QTableItem::EditType. Same collab energy as the column version ๐Ÿซถ

See also setRowReadOnly() and isColumnReadOnly().


bool QTable::isRowSelected ( int row, bool full = FALSE ) const

Returns TRUE if row row is selected; otherwise returns FALSE.

And again, the full tea:

  • If full is FALSE (the default), "row is selected" means that at least one cell in the row is selected.
  • If full is TRUE, then "row is selected" means every cell in the row is selected.

See also isColumnSelected() and isSelected().


bool QTable::isRowStretchable ( int row ) const [slot]

Returns TRUE if row row is stretchable; otherwise returns FALSE.

See also setRowStretchable() and isColumnStretchable().


bool QTable::isSelected ( int row, int col ) const

Returns TRUE if the cell at row, col is selected; otherwise returns FALSE. The most direct "are you chosen" question in the whole table ๐Ÿ’–

See also isRowSelected() and isColumnSelected().


QTableItem * QTable::item ( int row, int col ) const [virtual]

Returns the QTableItem representing the contents of the cell at row, col. That's the actual thing living in the cell ๐Ÿ 

If row or col are out of range, or no content has been set for this cell, item() returns 0. Empty cell, empty vibes ๐Ÿ˜ถ

If you don't use QTableItems, you may need to reimplement this function โ€” see the notes on large tables.

See also setItem().

Example: regexptester/regexptester.cpp.


int QTable::numCols () const [virtual]

Returns the number of columns in the table. See the "numCols" property for details. Count 'em up ๐Ÿ”ข

Reimplemented in QDataTable.


int QTable::numRows () const [virtual]

Returns the number of rows in the table. See the "numRows" property for details.

Reimplemented in QDataTable.


int QTable::numSelections () const

Returns the number of selections. See the "numSelections" property for details. How many things are currently highlighted, bestie โœจ


void QTable::paintCell ( QPainter * p, int row, int col, const QRect & cr, bool selected, const QColorGroup & cg ) [virtual]

Paints the cell at row, col on the painter p. Important detail: the painter has already been translated to the cell's origin. And cr describes the cell coordinates in the content coordinate system. ๐ŸŽจ

If selected is TRUE, the cell is highlighted. โœจ

cg is the colorgroup that should be used to draw the cell content. ๐ŸŒˆ

So you want custom cell content โ€” say, right-aligned text? You've got two paths, pick your fighter:

  • Reimplement paintCell(), or
  • Subclass QTableItem and reimplement QTableItem::paint() to do the custom drawing.

If you're using a QTableItem subclass โ€” for example to store a data structure โ€” then reimplementing QTableItem::paint() may be the best approach. But for data you want to draw immediately, e.g. data retrieved from a database, it's probably best to reimplement paintCell().

Careful though: if you reimplement paintCell(), i.e. you don't use QTableItems, you must reimplement other functions too โ€” see the notes on large tables. Don't skip that part, fr fr.

Also note the painter is not clipped by default, and that's on purpose, for maximum efficiency. If you want clipping, use code like this:

p->setClipRect( cellRect(row, col), QPainter::CoordPainter );
//... your drawing code
p->setClipping( FALSE );

void QTable::paintCell ( QPainter * p, int row, int col, const QRect & cr, bool selected ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Use the other paintCell() function. This one is only included for backwards compatibilty. (Yes, that's how the original spells it, and we respect the source ๐Ÿ˜Œ)

void QTable::paintEmptyArea ( QPainter * p, int cx, int cy, int cw, int ch ) [virtual protected]

This function fills the cw pixels wide and ch pixels high rectangle starting at position cx, cy with the background color, using the painter p. It's the "fill in the blanks" moment ๐Ÿ–Œ๏ธ

paintEmptyArea() is invoked by drawContents() to erase or fill unused areas. Cleaning up the leftovers, iconic ๐Ÿงน


void QTable::paintFocus ( QPainter * p, const QRect & cr ) [virtual]

Draws the focus rectangle of the current cell (see currentRow(), currentColumn()). Spotlight on the chosen one ๐Ÿ‘‘

The painter p is already translated to the cell's origin, while cr specifies the cell's geometry in content coordinates. ๐Ÿ“


QPixmap QTable::pixmap ( int row, int col ) const [virtual]

Returns the pixmap set for the cell at row, col, or a null-pixmap if the cell contains no pixmap. No picture, no problem ๐Ÿ–ผ๏ธ

See also setPixmap().

Example: chart/setdataform.cpp.


void QTable::pressed ( int row, int col, int button, const QPoint & mousePos ) [signal]

This signal is emitted when mouse button button is pressed. The cell where the event took place is at row, col, and the mouse's position is in mousePos. Click detected, tea incoming ๐Ÿ“ฉ

See also Qt::ButtonState.


void QTable::removeColumn ( int col ) [virtual slot]

Removes column col, and deletes all its cells including any table items and widgets the cells may contain. Also clears the selection(s).

This is a real delete, bestie. Items and widgets in there are gone-gone, not just hidden. ๐Ÿ˜ญ

See also removeColumns(), hideColumn(), insertColumns(), and removeRow().


void QTable::removeColumns ( const QMemArray<int> & cols ) [virtual slot]

Removes the columns listed in the array cols, and deletes all their cells including any table items and widgets the cells may contain. Bulk removal, we love efficiency ๐Ÿ’…

The array passed in must only contain valid columns (in the range from 0 to numCols() - 1) with no duplicates, and must be sorted in ascending order. Also clears the selection(s). Break these rules and you're on your own ๐Ÿ™ˆ

See also removeColumn(), insertColumns(), and removeRows().


void QTable::removeRow ( int row ) [virtual slot]

Removes row row, and deletes all its cells including any table items and widgets the cells may contain. Also clears the selection(s). Same deletion energy, row edition ๐ŸŒช๏ธ

See also hideRow(), insertRows(), removeColumn(), and removeRows().


void QTable::removeRows ( const QMemArray<int> & rows ) [virtual slot]

Removes the rows listed in the array rows, and deletes all their cells including any table items and widgets the cells may contain.

Same rules as removeColumns(): the array passed in must only contain valid rows (in the range from 0 to numRows() - 1) with no duplicates, and must be sorted in ascending order. Also clears the selection(s). โœ๏ธ

See also removeRow(), insertRows(), and removeColumns().


void QTable::removeSelection ( const QTableSelection & s ) [virtual]

If the table has a selection, s, this selection is removed from the table. Un-selecting, respectfully โœ‚๏ธ

See also addSelection() and numSelections.


void QTable::removeSelection ( int num ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Removes selection number num from the table. Bye selection #num ๐Ÿ‘‹

See also numSelections, addSelection(), and clearSelection().


void QTable::repaintSelections ()

Repaints all selections. That's it, that's the whole function โ€” a lil glow-up pass on every selection you've got โœจ๐ŸŽ€

void QTable::resizeData ( int len ) [virtual protected] โœจ

okay so this one gets called when QTable's internal array needs to be resized to len elements. no cap, it's giving "make room bestie".

If you don't use QTableItems you should reimplement this as an empty method to avoid wasting memory. See the notes on large tables for further details. ๐Ÿ’…


int QTable::rowAt ( int y ) const [virtual] ๐Ÿฆ‹

Returns the number of the row at position y. y must be given in content coordinates. iykyk

See also rowPos() and columnAt().


int QTable::rowHeight ( int row ) const [virtual] ๐ŸŒธ

Returns the height of row row. periodt

See also setRowHeight() and columnWidth().

Example: table/small-table-demo/main.cpp.


void QTable::rowHeightChanged ( int row ) [virtual protected slot] ๐Ÿ“

This function should be called whenever the row height of row has been changed. It updates the geometry of any affected rows and repaints the table to reflect the changes it has made. ๐Ÿ”ฅ


void QTable::rowIndexChanged ( int section, int fromIndex, int toIndex ) [virtual protected slot] ๐Ÿ’™

This function is called when the order of the rows is to be changed, i.e. the user moved the row header section section from fromIndex to toIndex. the way that works

If you want to change the order programmatically, call swapRows() or swapColumns();

See also QHeader::indexChange() and columnIndexChanged().


bool QTable::rowMovingEnabled () const ๐ŸŒฟ

Returns TRUE if rows can be moved by the user; otherwise returns FALSE. See the "rowMovingEnabled" property for details. ๐Ÿ‘‘


int QTable::rowPos ( int row ) const [virtual] ๐Ÿ’–

Returns the y-coordinate of the row row in content coordinates.

See also rowAt() and columnPos().


void QTable::selectCells ( int start_row, int start_col, int end_row, int end_col ) โœจ

Selects the range starting at start_row and start_col and ending at end_row and end_col. slay

See also QTableSelection.


void QTable::selectColumn ( int col ) ๐Ÿฆ‹

Selects the column col.

See also QTableSelection.


void QTable::selectRow ( int row ) ๐ŸŒธ

Selects the row row.

See also QTableSelection.


QTableSelection QTable::selection ( int num ) const ๐Ÿ’œ

Returns selection number num, or an inactive QTableSelection if num is out of range (see QTableSelection::isActive()). not me checking ranges


void QTable::selectionChanged () [signal] ๐ŸŒˆ

This signal is emitted whenever a selection changes. periodt

See also QTableSelection.


SelectionMode QTable::selectionMode () const ๐Ÿ’Ž

Returns the current selection mode. See the "selectionMode" property for details.


void QTable::setCellContentFromEditor ( int row, int col ) [virtual protected] ๐ŸŽ€

This function is called to replace the contents of the cell at row, col with the contents of the cell's editor. the way that editor content just slides in

If there already exists a QTableItem for the cell, it calls QTableItem::setContentFromEditor() on this QTableItem.

If, for example, you want to create different QTableItems depending on the contents of the editor, you might reimplement this function.

If you want to work without QTableItems, you will need to reimplement this function to save the data the user entered into your data structure. (See the notes on large tables.)

See also QTableItem::setContentFromEditor() and createEditor().


void QTable::setCellWidget ( int row, int col, QWidget * e ) [virtual] ๐Ÿ’…

Sets the widget e to the cell at row, col and takes care of placing and resizing the widget when the cell geometry changes. iconic behavior

By default widgets are inserted into a vector with numRows() * numCols() elements. In very large tables you will probably want to store the widgets in a data structure that consumes less memory (see the notes on large tables). To support the use of your own data structure this function calls insertWidget() to add the widget to the internal data structure. To use your own data structure reimplement insertWidget(), cellWidget() and clearCellWidget().

Cell widgets are created dynamically with the new operator. The cell widgets are destroyed automatically once the table is destroyed; the table takes ownership of the widget when using setCellWidget. no cap, table says mine now

Example: chart/setdataform.cpp.


void QTable::setColumnLabels ( const QStringList & labels ) [slot] ๐ŸŒธ

Sets the section labels of the horizontalHeader() to labels โœจ


void QTable::setColumnMovingEnabled ( bool b ) [virtual slot] ๐Ÿฆ‹

Sets whether columns can be moved by the user to b. See the "columnMovingEnabled" property for details.


void QTable::setColumnReadOnly ( int col, bool ro ) [virtual slot] ๐Ÿ“

If ro is TRUE, column col is set to be read-only; otherwise the column is set to be editable.

Whether a cell in this column is editable or read-only depends on the cell's EditType, and this setting: see QTableItem::EditType. iykyk

See also isColumnReadOnly(), setRowReadOnly(), and readOnly.

Example: chart/setdataform.cpp.


void QTable::setColumnStretchable ( int col, bool stretch ) [virtual slot] ๐ŸŒฟ

If stretch is TRUE, column col is set to be stretchable; otherwise column col is set to be unstretchable.

If the table widget's width decreases or increases stretchable columns will grow narrower or wider to fit the space available as completely as possible. The user cannot manually resize stretchable columns. the way it just adapts, main character energy

See also isColumnStretchable(), setRowStretchable(), and adjustColumn().


void QTable::setColumnWidth ( int col, int w ) [virtual slot] ๐Ÿ’–

Resizes column col to be w pixels wide.

See also columnWidth() and setRowHeight().

Example: chart/setdataform.cpp.

Reimplemented in QDataTable.


void QTable::setCurrentCell ( int row, int col ) [virtual slot] ๐Ÿ‘‘

Moves the focus to the cell at row, col. periodt

See also currentRow() and currentColumn().


void QTable::setDragEnabled ( bool b ) [virtual slot] ๐Ÿ’Ž

If b is TRUE, the table starts a drag (see dragObject()) when the user presses and moves the mouse on a selected cell. slay


void QTable::setEditMode ( EditMode mode, int row, int col ) [protected] ๐Ÿฆ‹

Sets the current edit mode to mode, the current edit row to row and the current edit column to col.

See also EditMode.


void QTable::setFocusStyle ( FocusStyle fs ) [virtual] ๐ŸŒธ

Sets how the current (focus) cell is drawn to fs. See the "focusStyle" property for details.


void QTable::setItem ( int row, int col, QTableItem * item ) [virtual] ๐ŸŒˆ

Inserts the table item item into the table at row row, column col, and repaints the cell. If a table item already exists in this cell it is deleted and replaced with item. The table takes ownership of the table item. no cap, it's giving "new item who dis"

If you don't use QTableItems you may need to reimplement this function: see the notes on large tables.

See also item() and takeItem().

Examples:


void QTable::setLeftMargin ( int m ) [virtual slot] ๐ŸŽ€

Sets the left margin to be m pixels wide.

The verticalHeader(), which displays row labels, occupies this margin.

In an Arabic or Hebrew localization, the verticalHeader() will appear on the right side of the table, and this call will set the right margin. the way localization flips the vibe

See also leftMargin(), setTopMargin(), and verticalHeader().

Example: regexptester/regexptester.cpp.


void QTable::setNumCols ( int r ) [virtual slot] โœจ

Sets the number of columns in the table to r. See the "numCols" property for details.


void QTable::setNumRows ( int r ) [virtual slot] ๐ŸŒธ

Sets the number of rows in the table to r. See the "numRows" property for details.


void QTable::setPixmap ( int row, int col, const QPixmap & pix ) [virtual] ๐Ÿ’…

Sets the pixmap in the cell at row, col to pix.

If the cell does not contain a table item a QTableItem is created with an EditType of OnTyping, otherwise the existing table item's pixmap (if any) is replaced with pix. the way that pixmap just moves in

Note that QComboTableItems and QCheckTableItems don't show pixmaps. sad but true

See also pixmap(), setText(), setItem(), and QTableItem::setPixmap().

Examples:


void QTable::setReadOnly ( bool b ) [virtual slot] ๐Ÿ“

Sets whether the table is read-only to b. See the "readOnly" property for details.


void QTable::setRowHeight ( int row, int h ) [virtual slot] ๐ŸŒฟ

Resizes row row to be h pixels high.

See also rowHeight() and setColumnWidth().


void QTable::setRowLabels ( const QStringList & labels ) [slot] ๐Ÿ’œ

Sets the section labels of the verticalHeader() to labels โœจ


void QTable::setRowMovingEnabled ( bool b ) [virtual slot] ๐Ÿฆ‹

Sets whether rows can be moved by the user to b. See the "rowMovingEnabled" property for details.


void QTable::setRowReadOnly ( int row, bool ro ) [virtual slot] ๐ŸŒธ

If ro is TRUE, row row is set to be read-only; otherwise the row is set to be editable.

Whether a cell in this row is editable or read-only depends on the cell's EditType, and this setting: see QTableItem::EditType. iykyk

See also isRowReadOnly(), setColumnReadOnly(), and readOnly.


void QTable::setRowStretchable ( int row, bool stretch ) [virtual slot] ๐Ÿ“

If stretch is TRUE, row row is set to be stretchable; otherwise row row is set to be unstretchable.

If the table widget's height decreases or increases stretchable rows will grow shorter or taller to fit the space available as completely as possible. The user cannot manually resize stretchable rows. the way it just fits, periodt

See also isRowStretchable() and setColumnStretchable().


void QTable::setSelectionMode ( SelectionMode mode ) [virtual] ๐Ÿ’–

Sets the current selection mode to mode. See the "selectionMode" property for details.


void QTable::setShowGrid ( bool b ) [virtual slot] ๐Ÿ’Ž

Sets whether the table's grid is displayed to b. See the "showGrid" property for details.


void QTable::setSorting ( bool b ) [virtual slot] ๐ŸŒฟ

Sets whether a click on the header of a column sorts that column to b. See the "sorting" property for details. slay sorting


void QTable::setText ( int row, int col, const QString & text ) [virtual] ๐Ÿ‘‘

Sets the text in the cell at row, col to text.

If the cell does not contain a table item a QTableItem is created with an EditType of OnTyping, otherwise the existing table item's text (if any) is replaced with text. the way that text just appears

See also text(), setPixmap(), setItem(), and QTableItem::setText().

Examples:


void QTable::setTopMargin ( int m ) [virtual slot] ๐ŸŽ€

Sets the top margin to be m pixels high.

The horizontalHeader(), which displays column labels, occupies this margin.

See also topMargin() and setLeftMargin().

Example: regexptester/regexptester.cpp.


void QTable::showColumn ( int col ) [virtual slot] ๐Ÿฆ‹

Shows column col.

See also hideColumn() and showRow().


bool QTable::showGrid () const โœจ

Returns TRUE if the table's grid is displayed; otherwise returns FALSE. See the "showGrid" property for details.


void QTable::showRow ( int row ) [virtual slot] ๐ŸŒธ

Shows row row.

See also hideRow() and showColumn(). ๐Ÿ’…

void QTable::sortColumn ( int col, bool ascending = TRUE, bool wholeRows = FALSE ) [virtual]

Sorts column col. If ascending is TRUE the sort goes โฌ†๏ธ ascending, otherwise it goes โฌ‡๏ธ descending.

If wholeRows is TRUE, entire rows get sorted using swapRows(); otherwise only the cells in that column get sorted using swapCells().

Heads up bestie ๐Ÿซถ โ€” if you're not using QTableItems you're gonna need to reimplement swapRows() and swapCells() yourself. (See the notes on large tables. iykyk ๐Ÿ’…)

See also swapRows().

Example: table/statistics/statistics.cpp.

Reimplemented in QDataTable.


bool QTable::sorting () const

Returns TRUE if a click on the header of a column sorts that column; otherwise returns FALSE. See the "sorting" property for details. โœจ


void QTable::startDrag () [virtual protected]

Starts a drag. ๐Ÿฆ‹

Usually you don't need to call or reimplement this function yourself โ€” it's giving internal plumbing, fr fr.

See also dragObject().


void QTable::swapCells ( int row1, int col1, int row2, int col2 ) [virtual slot]

Swaps the contents of the cell at row1, col1 with the contents of the cell at row2, col2. It's a straight-up trade, no takebacks ๐Ÿ’…

This function is also called when the table is sorted.

If you don't use QTableItems and want your users to be able to swap cells, you will need to reimplement this function. (See the notes on large tables.)

See also swapColumns() and swapRows().


void QTable::swapColumns ( int col1, int col2, bool swapHeader = FALSE ) [virtual slot]

Swaps the data in col1 with col2. โœจ

This function is used to swap the positions of two columns. It is called when the user changes the order of columns (see setColumnMovingEnabled()), and when columns are sorted.

If you don't use QTableItems and want your users to be able to swap columns you will need to reimplement this function. (See the notes on large tables.)

If swapHeader is TRUE, the columns' header contents is also swapped. ๐ŸŽ€

See also swapCells().


void QTable::swapRows ( int row1, int row2, bool swapHeader = FALSE ) [virtual slot]

Swaps the data in row1 and row2. ๐Ÿฆ‹

This function is used to swap the positions of two rows. It is called when the user changes the order of rows (see setRowMovingEnabled()), and when rows are sorted.

If you don't use QTableItems and want your users to be able to swap rows, e.g. for sorting, you will need to reimplement this function. (See the notes on large tables.)

If swapHeader is TRUE, the rows' header contents is also swapped.

Not this function being lazy ๐Ÿ˜ญ โ€” it will not update the QTable, you will have to do this manually, e.g. by calling updateContents().

See also swapColumns() and swapCells().


void QTable::takeItem ( QTableItem * i ) [virtual]

Takes the table item i out of the table. It's a gentle removal, not a delete: this function does not delete the table item. You must either delete the table item yourself or put it into a table (using setItem()) which will then take ownership of it. ๐Ÿ‘‘

Use this function if you want to move an item from one cell in a table to another, or to move an item from one table to another, reinserting the item with setItem().

If you want to exchange two cells use swapCells(). ๐Ÿซถ


QString QTable::text ( int row, int col ) const [virtual]

Returns the text in the cell at row, col, or QString::null if the relevant item does not exist or has no text. ๐Ÿ’€

See also setText() and setPixmap().

Example: chart/setdataform.cpp.

Reimplemented in QDataTable.


void QTable::updateCell ( int row, int col )

Repaints the cell at row, col. That's it, that's the whole vibe โ€” a lil refresh ๐ŸŽ€


void QTable::updateHeaderStates ()

This functions updates all the header states to be in sync with the current selections. This should be called after programatically changing, adding or removing selections, so that the headers are updated. โœจ

Bestie, remember this one โ€” if you change selections in code and the headers look stale, this is the glow-up they need. ๐Ÿ’…

void QTable::valueChanged ( int row, int col ) [signal]

This signal is emitted when the user changed the value in the cell at row, col. ๐Ÿ“ฃ

Example: chart/setdataform.cpp.


QHeader * QTable::verticalHeader () const

Returns the table's vertical QHeader. โฌ‡๏ธ

This header contains the row labels.

See also horizontalHeader(), setLeftMargin(), and QHeader.

Examples:

Not the docs just saying "Examples:" and then listing nothing ๐Ÿ˜ญ that's it. That's the whole list. fr fr. ๐Ÿ’€

๐ŸŽ€ PROPERTY DOCUMENTATION ๐ŸŽ€

bool columnMovingEnabled

This property holds whether columns can be moved by the user. ๐Ÿฆ‹

The default is FALSE. Columns are moved by dragging whilst holding down the Ctrl key.

Warning: If QTable is used to move header sections as a result of user interaction, the mapping between header indexes and section exposed by QHeader will not reflect the order of the headers in the table; i.e., QTable does not call QHeader::moveSection() to move sections but handles move operations internally. No cap, it's a whole thing. ๐Ÿ˜ญ

See also rowMovingEnabled.

Set this property's value with setColumnMovingEnabled() and get this property's value with columnMovingEnabled().


FocusStyle focusStyle

This property holds how the current (focus) cell is drawn. ๐Ÿ‘‘

The default style is SpreadSheet.

See also QTable::FocusStyle.

Set this property's value with setFocusStyle() and get this property's value with focusStyle().


int numCols

This property holds the number of columns in the table.

Set this property's value with setNumCols() and get this property's value with numCols().

See also numRows.


int numRows

This property holds the number of rows in the table.

Set this property's value with setNumRows() and get this property's value with numRows().

See also numCols.


int numSelections

This property holds the number of selections. โœจ

Get this property's value with numSelections().

See also currentSelection().


bool readOnly

This property holds whether the table is read-only. ๐Ÿ”’

Whether a cell in the table is editable or read-only depends on the cell's EditType, and this setting: see QTableItem::EditType.

See also QWidget::enabled, setColumnReadOnly(), and setRowReadOnly().

Set this property's value with setReadOnly() and get this property's value with isReadOnly().


bool rowMovingEnabled

This property holds whether rows can be moved by the user. ๐Ÿฆ‹

The default is FALSE. Rows are moved by dragging whilst holding down the Ctrl key.

Warning: If QTable is used to move header sections as a result of user interaction, the mapping between header indexes and section exposed by QHeader will not reflect the order of the headers in the table; i.e., QTable does not call QHeader::moveSection() to move sections but handles move operations internally. Same chaos, different axis. ๐Ÿ’€

See also columnMovingEnabled.

Set this property's value with setRowMovingEnabled() and get this property's value with rowMovingEnabled().


SelectionMode selectionMode

This property holds the current selection mode.

The default mode is Multi which allows the user to select multiple ranges of cells. ๐Ÿ’…

See also SelectionMode and selectionMode.

Set this property's value with setSelectionMode() and get this property's value with selectionMode().


bool showGrid

This property holds whether the table's grid is displayed.

The grid is shown by default. โœจ

Set this property's value with setShowGrid() and get this property's value with showGrid().


bool sorting

This property holds whether a click on the header of a column sorts that column. ๐Ÿ‘‘

Set this property's value with setSorting() and get this property's value with sorting().

See also sortColumn().


โœจ SEE ALSO โœจ


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


๐Ÿ’œ AUTHOR ๐Ÿ’œ

Generated automatically from the source code. ๐Ÿค– (the robots ate, no cap)


๐Ÿ› BUGS ๐Ÿ›

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. ๐Ÿซถ

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. (bestie we're the niche ๐Ÿ’…)

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qtable.3qt) and the Qt version (3.3.8). โœจ


And that's a wrap on QTable, bestie ๐ŸŽ€ this whole page was generated by Trolltech AS and stamped 2 February 2007, living on as QTable(3qt) โ€” go forth and build the most iconic tables, mwah ๐Ÿ’–

๐Ÿ“ฆ where this page comes from