![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QTableItem class provides the cell content in a QTable. More...
#include <qtable.h>
Inherits Qt.
Inherited by QComboTableItem and QCheckTableItem.
The QTableItem class provides the cell content in a QTable.
A QTableItem contains the data of a table cell and provides means to change them. It specifies whether and under which circumstances the cell might be edited by the user (see EditType) and the kind of editor that is used for changing its content.
Items may contain a text string and one pixmap each. If a pixmap has been defined it is presented to the left of the text. By default a QLineEdit that aligns its input to the left is provided for editing.
Furthermore, a QTableItem defines the cell size and the alignment of the displayed data. The item defines whether the respective cell data can be replaced, and whether word wrapping is desired when cell contents exceed the width of the cell. In addition the QTableItem class provides the API needed for sorting table items.
QTableItems are added to a QTable using QTable::setItem(). As long as they haven't been attached to the table this way QTable cells are empty.
To get rid of an item, simply delete it. By doing so, all required actions for removing it from the table are taken.
To define another editor you have to reimplement createEditor() and setContentFromEditor(). By reimplementing paint() and adding the relevant set- and "get"-functions custom subclasses of QTableItem may overcome the restriction of one text string and one pixmap per cell. If sorting is required reimplementing the key() function might be neccessary.
This enum is used to define whether a cell is editable or read-only
(possibly in conjunction with other settings) and how the cell should
be displayed.
Note that QComboTableItems 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.
QComboTableItems may be edited (i.e. interacted with) only if they are
editable in accordance with their EditType as described above.
Using this EditType ensures that the editor created with
createEditor() (by default a QLineEdit) is always visible. This has
implications on 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.
If a cell with the edit type Always looks misaligned you could
reimplement createEditor() for these items.
The OnTyping edit type is the default when QTableItem objects
are created by the convenience functions QTable::setText()
and QTable::setPixmap().
Member Function Documentation
QTableItem::QTableItem ( QTable * table, EditType et, const QString & text )
Creates a table item for the table table that contains the text
text. et determines its EditType.
To insert the item into a table use QTable::setItem():
QTableItem * discount = new QTableItem( this, QTableItem::Always, "-0.00" ); setItem( discountRow, 3, discount );
(Code taken from table/wineorder2/productlist.cpp )
Whilst the parent of the item (i.e. table) and the QTable it has been inserted into might occasionally be different, a table item can't be inserted into more than one tables at a time.
When shown in a table cell the pixmap appears to the left of text.
To insert the item into table (or another QTable object) use QTable::setItem().
Whilst the parent of the item (i.e. table) and the QTable it has been inserted into might occasionally be different, a table item can't be inserted into more than one tables at a time.
If the item has been attached to a table it is safely removed from it.
See also Qt::AlignmentFlags.
See also setSpan() and rowSpan().
If the function returns 0, the relevant cell cannot be edited.
The returned widget should preferably be unvisible, and it should have QTable::viewport() as parent.
If you reimplement this function, you probably also need to reimplement setContentFromEditor().
QWidget * SpinBoxItem::createEditor() const { QSpinBox * quantities = new QSpinBox( table->viewport(), "quantities" );
return quantities; }
(Code taken from table/wineorder2/spinboxitem.cpp )
See also QTable::createEditor(), setContentFromEditor() and QTable::viewport().
Example: table/wineorder2/spinboxitem.cpp.
This is determined at creation time of the item object. Items automatically created by the convenient functions QTable::setText() and QTable::setPixmap() default to QTableItem::OnTyping.
See also EditType and QTableItem().
See also setEnabled().
Note that this property is about exchanging one table item with another and not about whether the content of one item might be changed.
See also setReplaceable() and EditType.
Example: table/wineorder/productlist.cpp.
See also QTable::setSorting.
If selected is TRUE the cell is represented in a highlighted manner.
Usually you don't need to use this function but if you want to draw custom content in a cell you have to reimplement it.
In the default implementation no more than one pixmap per item are allowed.
See also setPixmap() and text().
See also setSpan() and colSpan().
Although often frowned upon by purists, Run Time Type Identification is very useful for QTables as it allows for an efficient indexed storage mechanism.
To distinguish between table items of various types create custom classes derived from QTableItem and make them return one unique rtti() value each. It is advisable to use values greater than 1000, preferably large random numbers, to allow for extensions to this class.
See also QCheckTableItem::rtti() and QComboTableItem::rtti().
Reimplemented in QComboTableItem and QCheckTableItem.
If the cell spans multiple columns, this function sets the leftmost column and retains the width.
See also col(), setRow() and colSpan().
You probably must reimplement this function if you reimplement createEditor() and return something that is not a QLineEdit.
void SpinBoxItem::setContentFromEditor( QWidget * spinbox ) { setText( ( (QSpinBox *) spinbox )->text() ); }
(Code taken from table/wineorder2/spinboxitem.cpp )
See also QTable::setCellContentFromEditor().
Example: table/wineorder2/spinboxitem.cpp.
A disabled item doesn't react to user input.
See also isEnabled().
If text() has been defined for the item the pixmap is by default presented on its left hand side.
Note that setPixmap() does not update the cell the item belongs to. Use QTable::updateCell() to repaint cell contents immediately.
For QComboTableItems and QCheckTableItems this function has no visible effect.
See also QTable::setPixmap(), pixmap() and setText().
Mind the difference between this property and the EditType that defines whether the user is able to change the content of a dedicated table item.
See also isReplaceable().
If the cell spans multiple rows, this function sets the top row and retains the height.
See also row(), setCol() and rowSpan().
See also rowSpan() and colSpan().
suffix = " btls";
setText( QString::number( value ) + suffix );
(Code taken from table/wineorder2/productlist.cpp and table/wineorder2/spinboxitem.cpp )
See also QTable::setText(), text(), setPixmap() and QTable::updateCell().
See also wordWrap().
Custom table items will often require reimplementation of this function.
Returns the QTable the item belongs to.
Note that this is the parent table object of the item even if the item fills a cell of another table.
See also QTable::setItem() and QTableItem().
See also setText() and pixmap().
See also setWordWrap().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version main-beta1
|