Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQTable Class Reference
[table module]

The TQTable class provides a flexible editable table widget. More...

#include <qtable.h>

Inherits TQScrollView.

Inherited by TQDataTable.

List of all member functions.

Public Members

Public Slots

Signals

Properties

Protected Members

Protected Slots


Detailed Description

The TQTable class provides a flexible editable table widget.

TQTable is easy to use, although it does have a large API because of the comprehensive functionality that it provides. TQTable includes functions for manipulating headers, rows and columns, cells and selections. TQTable also provides in-place editing and drag and drop, as well as a useful set of signals. TQTable efficiently supports very large tables, for example, tables one million by one million cells are perfectly possible. TQTable is economical with memory, using none for unused cells.

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

The first line constructs the table specifying its size in rows and columns. We then insert a pixmap and some text into the same cell, with the pixmap appearing to the left of the text. TQTable cells can be populated with TQTableItems, TQComboTableItems or by TQCheckTableItems. 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. (The numbers displayed start at 1, although row and column numbers within TQTable begin at 0.)

If you want to use mouse tracking call setMouseTracking( TRUE ) on the viewport; (see TQScrollView).

Table Items

Headers

TQTable 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 TQHeader::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.

Header labels are indexed via their section numbers. Note that the default behavior of TQHeader regarding section numbers is overriden for TQTable. See the explanation below in the Rows and Columns section in the discussion of moving columns and rows.

Rows and Columns

Row and column sizes are set with setRowHeight() and setColumnWidth(). If you want a row high enough to show the tallest item in its entirety, use adjustRow(). Similarly, to make a column wide enough to show the widest item use adjustColumn(). If you want the row height and column width to adjust automatically as the height and width of the table changes use setRowStretchable() and setColumnStretchable().

Rows and columns can be hidden and shown with hideRow(), hideColumn(), showRow() and showColumn(). New rows and columns are inserted using insertRows() and insertColumns(). Additional rows and columns are added at the bottom (rows) or right (columns) if you set setNumRows() or setNumCols() to be larger than numRows() or numCols(). Existing rows and columns are removed with removeRow() and removeColumn(). Multiple rows and columns can be removed with removeRows() and removeColumns().

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 TQHeader section numbers is overridden by TQTable. Currently in TQTable, 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 TQHeader. The TQTable TQHeader classes do not provide a mechanism for indexing independently of the user interface ordering.

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

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 TQTableItem::EditType.)

The row and column which have the focus are returned by currentRow() and currentColumn() respectively.

Although many TQTable functions operate in terms of rows and columns the indexOf() function returns a single integer identifying a particular cell.

Cells

All of a TQTable's cells are empty when the table is constructed.

There are two approaches to populating the table's cells. The first and simplest approach is to use TQTableItems or TQTableItem subclasses. The second approach doesn't use TQTableItems at all which is useful for very large sparse tables but retquires 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 TQTableItem 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 TQLineEdit. A pixmap may be put in a cell with setPixmap(), which also creates a table item if retquired. 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 TQTableItem or TQTableItem subclass, set its properties, then insert it into a cell with setItem().

If you want cells which contain comboboxes use the TQComboTableItem class. Similarly if you retquire cells containing checkboxes use the TQCheckTableItem class. These table items look and behave just like the combobox or checkbox widgets but consume far less memory.

        for ( int j = 0; j < numRows; ++j )
            table.setItem( j, 1, new TQCheckTableItem( &table, "Check me" ) );
In the example above we create a column of TQCheckTableItems and insert them into the table using setItem().

TQTable takes ownership of its TQTableItems 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 TQTableItems, and the values in TQComboTableItems and TQCheckTableItems works automatically. Cells may be editable or read-only, see TQTableItem::EditType. If you want fine control over editing see beginEdit() and endEdit().

The contents of a cell can be retrieved as a TQTableItem 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 TQTableItem 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 TQTableItems 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.

This approach retquires 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 TQTable 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 TQTableItems and TQWidgets, 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 TQTableItem documenation.

Selections

TQTable'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.

TQTable'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 TQTableSelection objects.

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

Alternatively, use addSelection() to add new selections using TQTableSelection objects. The advantage of using TQTableSelection objects is that you can call TQTableSelection::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().

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

TQTable::EditMode

TQTable::FocusStyle

Specifies how the current cell (focus cell) is drawn.

TQTable::SelectionMode


Member Function Documentation

TQTable::TQTable ( TQWidget * 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 TQTableItems.

See also TQWidget::clearWFlags() and TQt::WidgetFlags.

TQTable::TQTable ( int numRows, int numCols, TQWidget * 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 TQTableItems to populate the table's cells, you can create TQTableItem, TQComboTableItem and TQCheckTableItem items and insert them into the table using setItem(). (See the notes on large tables for an alternative to using TQTableItems.)

See also TQWidget::clearWFlags() and TQt::WidgetFlags.

TQTable::~TQTable ()

Releases all the resources used by the TQTable object, including all TQTableItems and their widgets.

void TQTable::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 TQTable::addSelection ( const TQTableSelection & 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 TQTableSelection::init() and TQTableSelection::expandTo() to make the selection valid (see also TQTableSelection::isActive(), or use the TQTableSelection(int,int,int,int) constructor).

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

void TQTable::adjustColumn ( int col ) [virtual slot]

Resizes column col so that the column width is wide enough to display the widest item the column contains.

See also adjustRow().

Example: regexptester/regexptester.cpp.

Reimplemented in TQDataTable.

void TQTable::adjustRow ( int row ) [virtual slot]

Resizes row row so that the row height is tall enough to display the tallest item the row contains.

See also adjustColumn().

TQWidget * TQTable::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.

See also endEdit().

TQRect TQTable::cellGeometry ( int row, int col ) const [virtual]

Returns the bounding rectangle of the cell at row, col in content coordinates.

TQRect TQTable::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 TQRect( TQPoint(0,0), cellGeometry( row, col).size() );

See also cellGeometry().

Example: chart/setdataform.cpp.

TQWidget * TQTable::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.

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

See also clearCellWidget() and setCellWidget().

Example: chart/setdataform.cpp.

void TQTable::clearCell ( int row, int col ) [virtual]

Removes the TQTableItem at row, col.

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

void TQTable::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 TQTableItems 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 TQObject::deleteLater() is called on the widget to avoid problems with timing issues.

See also cellWidget() and setCellWidget().

void TQTable::clearSelection ( bool repaint = TRUE ) [slot]

Clears all selections and repaints the appropriate regions if repaint is TRUE.

See also removeSelection().

void TQTable::clicked ( int row, int col, int button, const TQPoint & 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.

See also TQt::ButtonState.

Example: chart/setdataform.cpp.

int TQTable::columnAt ( int x ) const [virtual]

Returns the number of the column at position x. x must be given in content coordinates.

See also columnPos() and rowAt().

void TQTable::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.

void TQTable::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();

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

bool TQTable::columnMovingEnabled () const

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

int TQTable::columnPos ( int col ) const [virtual]

Returns the x-coordinate of the column col in content coordinates.

See also columnAt() and rowPos().

int TQTable::columnWidth ( int col ) const [virtual]

Returns the width of column col.

See also setColumnWidth() and rowHeight().

void TQTable::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.

void TQTable::contentsDragEnterEvent ( TQDragEnterEvent * e ) [virtual protected]

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

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

Reimplemented from TQScrollView.

void TQTable::contentsDragLeaveEvent ( TQDragLeaveEvent * e ) [virtual protected]

This event handler is called when a drag activity leaves this TQTable object with event e.

Reimplemented from TQScrollView.

void TQTable::contentsDragMoveEvent ( TQDragMoveEvent * e ) [virtual protected]

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

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

Reimplemented from TQScrollView.

void TQTable::contentsDropEvent ( TQDropEvent * e ) [virtual protected]

This event handler is called when the user ends a drag and drop by dropping something onto this TQTable and thus triggers the drop event, e.

Reimplemented from TQScrollView.

void TQTable::contextMenuRequested ( int row, int col, const TQPoint & 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.

TQWidget * TQTable::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 TQTableItem and the table item's TQTableItem::isReplaceable() is FALSE then the cell is asked to create an appropriate editor (using TQTableItem::createEditor()). Otherwise a TQLineEdit is used as the editor.

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

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

    TQTableItem *i = item( row, col );
    if ( initFromCell || ( i && !i->isReplaceable() ) )
        // If we had a TQTableItem ask the base class to create the editor
        return TQTable::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 TQTableItem::createEditor().

int TQTable::currEditCol () const [protected]

Returns the current edited column

int TQTable::currEditRow () const [protected]

Returns the current edited row

void TQTable::currentChanged ( int row, int col ) [signal]

This signal is emitted when the current cell has changed to row, col.

Example: chart/setdataform.cpp.

int TQTable::currentColumn () const

Returns the current column.

See also currentRow().

Example: chart/setdataform.cpp.

int TQTable::currentRow () const

Returns the current row.

See also currentColumn().

Example: chart/setdataform.cpp.

int TQTable::currentSelection () const [virtual]

Returns the number of the current selection or -1 if there is no current selection.

See also numSelections.

void TQTable::doubleClicked ( int row, int col, int button, const TQPoint & 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.

See also TQt::ButtonState.

bool TQTable::dragEnabled () const [slot]

If this function returns TRUE, the table supports dragging.

See also setDragEnabled().

TQDragObject * TQTable::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 TQDragObject depending on the selected items.

See also dropped().

void TQTable::drawContents ( TQPainter * 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 TQScrollView.

void TQTable::dropped ( TQDropEvent * e ) [signal]

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

e contains information about the drop.

void TQTable::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.

See also beginEdit().

EditMode TQTable::editMode () const [protected]

Returns the current edit mode

See also TQTable::EditMode.

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

This function is called when in-place editing of the cell at row, col is requested to stop.

If the cell is not being edited or accept is FALSE the function returns and the cell's contents are left unchanged.

If accept is TRUE the content of the editor must be transferred to the relevant cell. If replace is TRUE the current content of this cell should be replaced by the content of the editor (this means removing the current TQTableItem of the cell and creating a new one for the cell). Otherwise (if possible) the content of the editor should just be set to the existing TQTableItem of this cell.

setCellContentFromEditor() is called to replace the contents of the cell with the contents of the cell's editor.

Finally clearCellWidget() is called to remove the editor widget.

See also setCellContentFromEditor() and beginEdit().

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

Scrolls the table until the cell at row, col becomes visible.

FocusStyle TQTable::focusStyle () const

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

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

Hides column col.

See also showColumn() and hideRow().

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

Hides row row.

See also showRow() and hideColumn().

TQHeader * TQTable::horizontalHeader () const

Returns the table's top TQHeader.

This header contains the column labels.

To modify a column label use TQHeader::setLabel(), e.g.

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

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

Examples: chart/setdataform.cpp, helpsystem/mainwindow.cpp, regexptester/regexptester.cpp, and table/small-table-demo/main.cpp.

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

Returns a single integer which identifies a particular row and col by mapping the 2D table to a 1D array.

This is useful, for example, if you have a sparse table and want to use a TQIntDict to map integers to the cells that are used.

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

Inserts count empty columns at column col. Also clears the selection(s).

See also insertRows() and removeColumn().

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

Inserts count empty rows at row row. Also clears the selection(s).

See also insertColumns() and removeRow().

void TQTable::insertWidget ( int row, int col, TQWidget * w ) [virtual protected]

Inserts widget w at row, col into the internal data structure. See the documentation of setCellWidget() for further details.

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

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

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

See also hideColumn() and isRowHidden().

bool TQTable::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 TQTableItem::EditType.

See also setColumnReadOnly() and isRowReadOnly().

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

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

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 TQTable::isColumnStretchable ( int col ) const [slot]

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

See also setColumnStretchable() and isRowStretchable().

bool TQTable::isEditing () const [protected]

Returns TRUE if the EditMode is Editing or Replacing; otherwise (i.e. the EditMode is NotEditing) returns FALSE.

See also TQTable::EditMode.

bool TQTable::isReadOnly () const

Returns TRUE if the table is read-only; otherwise returns FALSE. See the "readOnly" property for details.

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

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

See also hideRow() and isColumnHidden().

bool TQTable::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 TQTableItem::EditType.

See also setRowReadOnly() and isColumnReadOnly().

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

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

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 TQTable::isRowStretchable ( int row ) const [slot]

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

See also setRowStretchable() and isColumnStretchable().

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

Returns TRUE if the cell at row, col is selected; otherwise returns FALSE.

See also isRowSelected() and isColumnSelected().

TQTableItem * TQTable::item ( int row, int col ) const [virtual]

Returns the TQTableItem representing the contents of the cell at row, col.

If row or col are out of range or no content has been set for this cell, item() returns 0.

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

See also setItem().

Example: regexptester/regexptester.cpp.

int TQTable::numCols () const [virtual]

Returns the number of columns in the table. See the "numCols" property for details.

Reimplemented in TQDataTable.

int TQTable::numRows () const [virtual]

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

Reimplemented in TQDataTable.

int TQTable::numSelections () const

Returns the number of selections. See the "numSelections" property for details.

void TQTable::paintCell ( TQPainter * p, int row, int col, const TQRect & cr, bool selected, const TQColorGroup & cg ) [virtual]

Paints the cell at row, col on the painter p. The painter has already been translated to the cell's origin. cr describes the cell coordinates in the content coordinate system.

If selected is TRUE the cell is highlighted.

cg is the colorgroup which should be used to draw the cell content.

If you want to draw custom cell content, for example right-aligned text, you must either reimplement paintCell(), or subclass TQTableItem and reimplement TQTableItem::paint() to do the custom drawing.

If you're using a TQTableItem subclass, for example, to store a data structure, then reimplementing TQTableItem::paint() may be the best approach. For data you want to draw immediately, e.g. data retrieved from a database, it is probably best to reimplement paintCell(). Note that if you reimplement paintCell(), i.e. don't use TQTableItems, you must reimplement other functions: see the notes on large tables.

Note that the painter is not clipped by default in order to get maximum efficiency. If you want clipping, use code like this:

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

void TQTable::paintCell ( TQPainter * p, int row, int col, const TQRect & 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 function is only included for backwards compatibilty.

void TQTable::paintEmptyArea ( TQPainter * 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.

paintEmptyArea() is invoked by drawContents() to erase or fill unused areas.

void TQTable::paintFocus ( TQPainter * p, const TQRect & cr ) [virtual]

Draws the focus rectangle of the current cell (see currentRow(), currentColumn()).

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

TQPixmap TQTable::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.

See also setPixmap().

Example: chart/setdataform.cpp.

void TQTable::pressed ( int row, int col, int button, const TQPoint & 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.

See also TQt::ButtonState.

void TQTable::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).

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

void TQTable::removeColumns ( const TQMemArray<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.

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

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

void TQTable::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).

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

void TQTable::removeRows ( const TQMemArray<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.

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 TQTable::removeSelection ( const TQTableSelection & s ) [virtual]

If the table has a selection, s, this selection is removed from the table.

See also addSelection() and numSelections.

void TQTable::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.

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

void TQTable::repaintSelections ()

Repaints all selections

void TQTable::resizeData ( int len ) [virtual protected]

This is called when TQTable's internal array needs to be resized to len elements.

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

int TQTable::rowAt ( int y ) const [virtual]

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

See also rowPos() and columnAt().

int TQTable::rowHeight ( int row ) const [virtual]

Returns the height of row row.

See also setRowHeight() and columnWidth().

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

void TQTable::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 TQTable::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.

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

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

bool TQTable::rowMovingEnabled () const

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

int TQTable::rowPos ( int row ) const [virtual]

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

See also rowAt() and columnPos().

void TQTable::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.

See also TQTableSelection.

void TQTable::selectColumn ( int col )

Selects the column col.

See also TQTableSelection.

void TQTable::selectRow ( int row )

Selects the row row.

See also TQTableSelection.

TQTableSelection TQTable::selection ( int num ) const

Returns selection number num, or an inactive TQTableSelection if num is out of range (see TQTableSelection::isActive()).

void TQTable::selectionChanged () [signal]

This signal is emitted whenever a selection changes.

See also TQTableSelection.

SelectionMode TQTable::selectionMode () const

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

void TQTable::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.

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

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

If you want to work without TQTableItems, 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 TQTableItem::setContentFromEditor() and createEditor().

void TQTable::setCellWidget ( int row, int col, TQWidget * 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.

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.

Example: chart/setdataform.cpp.

void TQTable::setColumnLabels ( const TQStringList & labels ) [slot]

Sets the section labels of the horizontalHeader() to labels

void TQTable::setColumnMovingEnabled ( bool b ) [virtual slot]

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

void TQTable::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 TQTableItem::EditType.

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

Example: chart/setdataform.cpp.

void TQTable::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.

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

void TQTable::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 TQDataTable.

void TQTable::setCurrentCell ( int row, int col ) [virtual slot]

Moves the focus to the cell at row, col.

See also currentRow() and currentColumn().

void TQTable::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.

void TQTable::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 TQTable::setFocusStyle ( FocusStyle fs ) [virtual]

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

void TQTable::setItem ( int row, int col, TQTableItem * 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.

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

See also item() and takeItem().

Examples: helpsystem/mainwindow.cpp and table/small-table-demo/main.cpp.

void TQTable::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.

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

Example: regexptester/regexptester.cpp.

void TQTable::setNumCols ( int r ) [virtual slot]

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

void TQTable::setNumRows ( int r ) [virtual slot]

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

void TQTable::setPixmap ( int row, int col, const TQPixmap & pix ) [virtual]

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

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

Note that TQComboTableItems and TQCheckTableItems don't show pixmaps.

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

Examples: chart/setdataform.cpp and table/small-table-demo/main.cpp.

void TQTable::setReadOnly ( bool b ) [virtual slot]

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

void TQTable::setRowHeight ( int row, int h ) [virtual slot]

Resizes row row to be h pixels high.

See also rowHeight() and setColumnWidth().

void TQTable::setRowLabels ( const TQStringList & labels ) [slot]

Sets the section labels of the verticalHeader() to labels

void TQTable::setRowMovingEnabled ( bool b ) [virtual slot]

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

void TQTable::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 TQTableItem::EditType.

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

void TQTable::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.

See also isRowStretchable() and setColumnStretchable().

void TQTable::setSelectionMode ( SelectionMode mode ) [virtual]

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

void TQTable::setShowGrid ( bool b ) [virtual slot]

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

void TQTable::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.

void TQTable::setText ( int row, int col, const TQString & text ) [virtual]

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

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

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

Examples: chart/setdataform.cpp, helpsystem/mainwindow.cpp, regexptester/regexptester.cpp, and table/small-table-demo/main.cpp.

void TQTable::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 TQTable::showColumn ( int col ) [virtual slot]

Shows column col.

See also hideColumn() and showRow().

bool TQTable::showGrid () const

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

void TQTable::showRow ( int row ) [virtual slot]

Shows row row.

See also hideRow() and showColumn().

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

Sorts column col. If ascending is TRUE the sort is in ascending order, otherwise the sort is in descending order.

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

Note that if you are not using TQTableItems you will need to reimplement swapRows() and swapCells(). (See the notes on large tables.)

See also swapRows().

Example: table/statistics/statistics.cpp.

Reimplemented in TQDataTable.

bool TQTable::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 TQTable::startDrag () [virtual protected]

Starts a drag.

Usually you don't need to call or reimplement this function yourself.

See also dragObject().

void TQTable::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.

This function is also called when the table is sorted.

If you don't use TQTableItems 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 TQTable::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 TQTableItems 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 TQTable::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 TQTableItems 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.

This function will not update the TQTable, you will have to do this manually, e.g. by calling updateContents().

See also swapColumns() and swapCells().

void TQTable::takeItem ( TQTableItem * i ) [virtual]

Takes the table item i out of the table. 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().

TQString TQTable::text ( int row, int col ) const [virtual]

Returns the text in the cell at row, col, or TQString::null if the relevant item does not exist or has no text.

See also setText() and setPixmap().

Example: chart/setdataform.cpp.

Reimplemented in TQDataTable.

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

Repaints the cell at row, col.

void TQTable::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.

void TQTable::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.

TQHeader * TQTable::verticalHeader () const

Returns the table's vertical TQHeader.

This header contains the row labels.

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

Examples: helpsystem/mainwindow.cpp and regexptester/regexptester.cpp.


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 TQTable is used to move header sections as a result of user interaction, the mapping between header indexes and section exposed by TQHeader will not reflect the order of the headers in the table; i.e., TQTable does not call TQHeader::moveSection() to move sections but handles move operations internally.

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 TQTable::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 TQTableItem::EditType.

See also TQWidget::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 TQTable is used to move header sections as a result of user interaction, the mapping between header indexes and section exposed by TQHeader will not reflect the order of the headers in the table; i.e., TQTable does not call TQHeader::moveSection() to move sections but handles move operations internally.

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


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8