For many applications TQTableItems are ideal for presenting and editing the contents of TQTable cells. In situations where you need to create very large tables you may prefer an alternative approach to using TQTableItems: see the notes on large tables.
A TQTableItem contains a cell's data, by default, a string and a pixmap. The table item also holds the cell's display size and how the data should be aligned. The table item specifies the cell's EditType and the editor used for in-place editing (by default a TQLineEdit). If you want checkboxes use TQCheckTableItem, and if you want comboboxes use TQComboTableItem. The EditType (set in the constructor) determines whether the cell's contents may be edited.
If a pixmap is specified it is displayed to the left of any text. You can change the text or pixmap with setText() and setPixmap() respectively. For text you can use setWordWrap().
.PP
When sorting table items the key() function is used; by default this returns the table item's text(). Reimplement key() to customize how your table items will sort.
Table items are inserted into a table using TQTable::setItem(). If you insert an item into a cell that already contains a table item the original item will be deleted.
You can move a table item from one cell to another, in the same or a different table, using TQTable::takeItem() and TQTable::setItem() but see also TQTable::swapCells().
Table items can be deleted with delete in the standard way; the table and cell will be updated accordingly.
.PP
Note, that if you have a table item that is not currently in a table then anything you do to that item other than insert it into a table will result in undefined behaviour.
Reimplement createEditor() and setContentFromEditor() if you want to use your own widget instead of a TQLineEdit for editing cell contents. Reimplement paint() if you want to display custom content.
It is important to ensure that your custom widget can accept the keyboard focus, so that the user can use the tab key to navigate the table as normal. Therefore, if the widget returned by createEditor() does not itself accept the keyboard focus, it is necessary to nominate a child widget to do so on its behalf. For example, a TQHBox with two child TQLineEdit widgets may use one of them to accept the keyboard focus:
By default, table items may be replaced by new TQTableItems during the lifetime of a TQTable. Therefore, if you create your own subclass of TQTableItem, and you want to ensure that this does not happen, you must call setReplaceable(FALSE) in the constructor of your subclass.
Using this EditType ensures that the editor created with createEditor() (by default a TQLineEdit) is always visible. This has implications for the alignment of the content: the default editor aligns everything (even numbers) to the left whilst numerical values in the cell are by default aligned to the right.
\fCTQTableItem::OnTyping\fR - The cell \fIlooks\fR editable only when the user types in it or double-clicks it. It resembles the WhenCurrent functionality but is, perhaps, nicer.
The cell is actually editable only if TQTable::isRowReadOnly() is FALSE for its row, TQTable::isColumnReadOnly() is FALSE for its column, and TQTable::isReadOnly() is FALSE.
TQComboTableItems have an isEditable() property. This property is used to indicate whether the user may enter their own text or are restricted to choosing one of the choices in the list. TQComboTableItems may be interacted with only if they are editable in accordance with their EditType as described above.
The table item will use a TQLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table with TQTable::setItem().
The table item will use a TQLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table with TQTable::setItem().
The table item will display the pixmap to the left of the text. It will use a TQLineEdit for editing the text, will not word-wrap and will occupy a single cell. Insert the table item into a table with TQTable::setItem().
The alignment function returns how the text contents of the cell are aligned when drawn. The default implementation aligns numbers to the right and any other text to the left.
This function returns whether the contents of the cell may be replaced with the contents of another table item. Regardless of this setting, table items that span more than one cell may not have their contents replaced by another table item.
.PP
(This differs from EditType because EditType is concerned with whether the \fIuser\fR is able to change the contents of a cell.)
This virtual function is used to paint the contents of an item using the painter \fIp\fR in the rectangular area \fIcr\fR using the color group \fIcg\fR.
.PP
If \fIselected\fR is TRUE the cell is displayed in a way that indicates that it is highlighted.
.PP
You don't usually need to use this function but if you want to draw custom content in a cell you will need to reimplement it.
.PP
The painter passed to this function is translated so that 0, 0 is the top-left corner of the item that is being painted.
.PP
Note that the painter is not clipped by default in order to get maximum efficiency. If you want clipping, use
When you create subclasses based on TQTableItem make sure that each subclass returns a unique rtti() value. It is advisable to use values greater than 1000, preferably large random numbers, to allow for extensions to this class.
See also TQTable::setPixmap(), pixmap(), and setText().
.SH "void TQTableItem::setReplaceable ( bool b )\fC [virtual]\fR"
If \fIb\fR is TRUE it is acceptable to replace the contents of the cell with the contents of another TQTableItem. If \fIb\fR is FALSE the contents of the cell may not be replaced by the contents of another table item. Table items that span more than one cell may not have their contents replaced by another table item.
.SH "void TQTableItem::setSpan ( int rs, int cs )\fC [virtual]\fR"
Changes the extent of the TQTableItem so that it spans multiple cells covering \fIrs\fR rows and \fIcs\fR columns. The top left cell is the original cell.
\fBWarning:\fR This function only works if the item has already been inserted into the table using e.g. TQTable::setItem(). This function also checks to make sure if \fIrs\fR and \fIcs\fR are within the bounds of the table and returns without changing the span if they are not. In addition swapping, inserting or removing rows and columns that cross TQTableItems spanning more than one cell is not supported.
If \fIb\fR is TRUE, the cell's text will be wrapped over multiple lines, when necessary, to fit the width of the cell; otherwise the text will be written as a single line.
This means that text() returns the original text value of the item if the editor is a line edit, until the user commits an edit (e.g. by pressing Enter or Tab) in which case the new text is returned. For other editors (e.g. a combobox) setContentFromEditor() is always called so the currently display value is the one returned.