Eneboo - Documentación para desarrolladores
|
The QTableItem class provides the cell content for QTable cells.table. Más...
#include <qtable.h>
Tipos públicos | |
enum | EditType { Never, OnTyping, WhenCurrent, Always, Never, OnTyping, WhenCurrent, Always } |
enum | EditType { Never, OnTyping, WhenCurrent, Always, Never, OnTyping, WhenCurrent, Always } |
Métodos públicos | |
QTableItem (QTable *table, EditType et) | |
QTableItem (QTable *table, EditType et, const QString &text) | |
QTableItem (QTable *table, EditType et, const QString &text, const QPixmap &p) | |
virtual | ~QTableItem () |
virtual QPixmap | pixmap () const |
virtual QString | text () const |
virtual void | setPixmap (const QPixmap &p) |
virtual void | setText (const QString &t) |
QTable * | table () const |
virtual int | alignment () const |
virtual void | setWordWrap (bool b) |
bool | wordWrap () const |
EditType | editType () const |
virtual QWidget * | createEditor () const |
virtual void | setContentFromEditor (QWidget *w) |
virtual void | setReplaceable (bool) |
bool | isReplaceable () const |
virtual QString | key () const |
virtual QSize | sizeHint () const |
virtual void | setSpan (int rs, int cs) |
int | rowSpan () const |
int | colSpan () const |
virtual void | setRow (int r) |
virtual void | setCol (int c) |
int | row () const |
int | col () const |
virtual void | paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected) |
void | updateEditor (int oldRow, int oldCol) |
virtual void | setEnabled (bool b) |
bool | isEnabled () const |
virtual int | rtti () const |
QTableItem (QTable *table, EditType et) | |
QTableItem (QTable *table, EditType et, const QString &text) | |
QTableItem (QTable *table, EditType et, const QString &text, const QPixmap &p) | |
virtual | ~QTableItem () |
virtual QPixmap | pixmap () const |
virtual QString | text () const |
virtual void | setPixmap (const QPixmap &p) |
virtual void | setText (const QString &t) |
QTable * | table () const |
virtual int | alignment () const |
virtual void | setWordWrap (bool b) |
bool | wordWrap () const |
EditType | editType () const |
virtual QWidget * | createEditor () const |
virtual void | setContentFromEditor (QWidget *w) |
virtual void | setReplaceable (bool) |
bool | isReplaceable () const |
virtual QString | key () const |
virtual QSize | sizeHint () const |
virtual void | setSpan (int rs, int cs) |
int | rowSpan () const |
int | colSpan () const |
virtual void | setRow (int r) |
virtual void | setCol (int c) |
int | row () const |
int | col () const |
virtual void | paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected) |
void | updateEditor (int oldRow, int oldCol) |
virtual void | setEnabled (bool b) |
bool | isEnabled () const |
virtual int | rtti () const |
Atributos públicos estáticos | |
static int | RTTI = 0 |
Amigas | |
class | QTable |
The QTableItem class provides the cell content for QTable cells.
table.
For many applications QTableItems are ideal for presenting and editing the contents of QTable cells. In situations where you need to create very large tables you may prefer an alternative approach to using QTableItems: see the notes on large tables.
A QTableItem 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 QLineEdit). If you want checkboxes use {QCheckTableItem}, and if you want comboboxes use {QComboTableItem}. 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().
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 QTable::setItem(). If you insert an item into a cell that already contains a table item the original item will be deleted.
Example:
for ( int row = 0; row < table->numRows(); row++ ) { for ( int col = 0; col < table->numCols(); col++ ) { table->setItem( row, col, new QTableItem( table, QTableItem::WhenCurrent, QString::number( row * col ) ) ); } }
You can move a table item from one cell to another, in the same or a different table, using QTable::takeItem() and QTable::setItem() but see also QTable::swapCells().
Table items can be deleted with delete in the standard way; the table and cell will be updated accordingly.
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 QLineEdit 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 QHBox with two child QLineEdit widgets may use one of them to accept the keyboard focus:
QWidget* MyTableItem::createEditor() const { QHBox* hbox = new QHBox( table()->viewport() ); hbox->setFocusProxy(new QLineEdit( hbox )); new QLineEdit( hbox ); return hbox; }
By default, table items may be replaced by new QTableItems during the lifetime of a QTable. Therefore, if you create your own subclass of QTableItem, and you want to ensure that this does not happen, you must call setReplaceable(FALSE) in the constructor of your subclass.
qtableitems.png Table Items
enum QTableItem::EditType |
wheneditable This enum is used to define whether a cell is editable or read-only (in conjunction with other settings), and how the cell should be displayed.
Always The cell always looks editable.
Using this EditType ensures that the editor created with createEditor() (by default a QLineEdit) 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.
If a cell with the edit type Always
looks misaligned you could reimplement createEditor() for these items.
WhenCurrent The cell looks editable only when it has keyboard focus (see QTable::setCurrentCell()).
OnTyping The cell looks editable only when the user types in it or double-clicks it. It resembles the WhenCurrent
functionality but is, perhaps, nicer.
The OnTyping
edit type is the default when QTableItem objects are created by the convenience functions QTable::setText() and QTable::setPixmap().
Never The cell is not editable.
The cell is actually editable only if QTable::isRowReadOnly() is FALSE for its row, QTable::isColumnReadOnly() is FALSE for its column, and QTable::isReadOnly() is FALSE.
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 interacted with only if they are editable in accordance with their EditType as described above.
enum QTableItem::EditType |
Creates a table item that is a child of table table with no text. The item has the EditType et.
The table item will use a QLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table with QTable::setItem().
The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.
Creates a table item that is a child of table table with text text. The item has the EditType et.
The table item will use a QLineEdit for its editor, will not word-wrap and will occupy a single cell. Insert the table item into a table with QTable::setItem().
The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.
Creates a table item that is a child of table table with text text and pixmap p. The item has the EditType et.
The table item will display the pixmap to the left of the text. It will use a QLineEdit for editing the text, will not word-wrap and will occupy a single cell. Insert the table item into a table with QTable::setItem().
The table takes ownership of the table item, so a table item should not be inserted in more than one table at a time.
QTableItem::~QTableItem | ( | ) | [virtual] |
The destructor deletes this item and frees all allocated resources.
If the table item is in a table (i.e. was inserted with setItem()), it will be removed from the table and the cell it occupied.
virtual QTableItem::~QTableItem | ( | ) | [virtual] |
int QTableItem::alignment | ( | ) | const [virtual] |
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.
virtual int QTableItem::alignment | ( | ) | const [virtual] |
int QTableItem::col | ( | ) | const |
int QTableItem::col | ( | ) | const |
int QTableItem::colSpan | ( | ) | const |
int QTableItem::colSpan | ( | ) | const |
QWidget * QTableItem::createEditor | ( | ) | const [virtual] |
This virtual function creates an editor which the user can interact with to edit the cell's contents. The default implementation creates a QLineEdit.
If the function returns 0, the cell is read-only.
The returned widget should preferably be invisible, ideally with QTable::viewport() as parent.
If you reimplement this function you'll almost certainly need to reimplement setContentFromEditor(), and may need to reimplement sizeHint().
table/statistics/statistics.cpp createEditor }
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem, QCheckTableItem, SenderItem, ReceiverItem, SignalItem y SlotItem.
virtual QWidget* QTableItem::createEditor | ( | ) | const [virtual] |
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem, QCheckTableItem, SenderItem, ReceiverItem, SignalItem y SlotItem.
EditType QTableItem::editType | ( | ) | const |
QTableItem::EditType QTableItem::editType | ( | ) | const |
Returns the table item's edit type.
This is set when the table item is constructed.
bool QTableItem::isEnabled | ( | ) | const |
Returns TRUE if the table item is enabled; otherwise returns FALSE.
bool QTableItem::isEnabled | ( | ) | const |
bool QTableItem::isReplaceable | ( | ) | const |
bool QTableItem::isReplaceable | ( | ) | const |
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.
(This differs from EditType because EditType is concerned with whether the user is able to change the contents of a cell.)
virtual QString QTableItem::key | ( | ) | const [virtual] |
QString QTableItem::key | ( | ) | const [virtual] |
This virtual function returns the key that should be used for sorting. The default implementation returns the text() of the relevant item.
void QTableItem::paint | ( | QPainter * | p, |
const QColorGroup & | cg, | ||
const QRect & | cr, | ||
bool | selected | ||
) | [virtual] |
This virtual function is used to paint the contents of an item using the painter p in the rectangular area cr using the color group cg.
If selected is TRUE the cell is displayed in a way that indicates that it is highlighted.
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.
The painter passed to this function is translated so that 0, 0 is the top-left corner of the item that is being painted.
Note that the painter is not clipped by default in order to get maximum efficiency. If you want clipping, use
p->setClipRect( table()->cellRect(row, col), QPainter::ClipPainter ); //... your drawing code p->setClipping( FALSE );
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem, QCheckTableItem y ConnectionItem.
virtual void QTableItem::paint | ( | QPainter * | p, |
const QColorGroup & | cg, | ||
const QRect & | cr, | ||
bool | selected | ||
) | [virtual] |
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem, QCheckTableItem y ConnectionItem.
QPixmap QTableItem::pixmap | ( | ) | const [virtual] |
Returns the table item's pixmap or a null pixmap if no pixmap has been set.
virtual QPixmap QTableItem::pixmap | ( | ) | const [virtual] |
int QTableItem::row | ( | ) | const |
int QTableItem::row | ( | ) | const |
int QTableItem::rowSpan | ( | ) | const |
int QTableItem::rowSpan | ( | ) | const |
virtual int QTableItem::rtti | ( | ) | const [virtual] |
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
int QTableItem::rtti | ( | ) | const [virtual] |
Returns the Run Time Type Identification value for this table item which for QTableItems is 0.
When you create subclasses based on QTableItem 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.
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
void QTableItem::setCol | ( | int | c | ) | [virtual] |
virtual void QTableItem::setCol | ( | int | c | ) | [virtual] |
virtual void QTableItem::setContentFromEditor | ( | QWidget * | w | ) | [virtual] |
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
void QTableItem::setContentFromEditor | ( | QWidget * | w | ) | [virtual] |
Whenever the content of a cell has been edited by the editor w, QTable calls this virtual function to copy the new values into the QTableItem.
If you reimplement createEditor() and return something that is not a QLineEdit you will need to reimplement this function.
table/statistics/statistics.cpp setContentFromEditor }
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
void QTableItem::setEnabled | ( | bool | b | ) | [virtual] |
If b is TRUE, the table item is enabled; if b is FALSE the table item is disabled.
A disabled item doesn't respond to user interaction.
virtual void QTableItem::setEnabled | ( | bool | b | ) | [virtual] |
void QTableItem::setPixmap | ( | const QPixmap & | p | ) | [virtual] |
Sets pixmap p to be this item's pixmap.
Note that setPixmap() does not update the cell the table item belongs to. Use QTable::updateCell() to repaint the cell's contents.
For {QComboTableItem}s and {QCheckTableItem}s this function has no visible effect.
virtual void QTableItem::setPixmap | ( | const QPixmap & | p | ) | [virtual] |
virtual void QTableItem::setReplaceable | ( | bool | ) | [virtual] |
void QTableItem::setReplaceable | ( | bool | b | ) | [virtual] |
If b is TRUE it is acceptable to replace the contents of the cell with the contents of another QTableItem. If b 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.
(This differs from EditType because EditType is concerned with whether the user is able to change the contents of a cell.)
virtual void QTableItem::setRow | ( | int | r | ) | [virtual] |
void QTableItem::setRow | ( | int | r | ) | [virtual] |
Changes the extent of the QTableItem so that it spans multiple cells covering rs rows and cs columns. The top left cell is the original cell.
void QTableItem::setText | ( | const QString & | str | ) | [virtual] |
Changes the table item's text to str.
Note that setText() does not update the cell the table item belongs to. Use QTable::updateCell() to repaint the cell's contents.
Reimplementado en QCheckTableItem y QCheckTableItem.
virtual void QTableItem::setText | ( | const QString & | t | ) | [virtual] |
Reimplementado en QCheckTableItem y QCheckTableItem.
virtual void QTableItem::setWordWrap | ( | bool | b | ) | [virtual] |
void QTableItem::setWordWrap | ( | bool | b | ) | [virtual] |
If b 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.
virtual QSize QTableItem::sizeHint | ( | ) | const [virtual] |
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
QSize QTableItem::sizeHint | ( | ) | const [virtual] |
This virtual function returns the size a cell needs to show its entire content.
If you subclass QTableItem you will often need to reimplement this function.
Reimplementado en QComboTableItem, QCheckTableItem, QComboTableItem y QCheckTableItem.
QTable* QTableItem::table | ( | ) | const [inline] |
QTable * QTableItem::table | ( | ) | const [inline] |
Returns the QTable the table item belongs to.
QString QTableItem::text | ( | ) | const [virtual] |
Returns the text of the table item or QString::null if there is no text.
To ensure that the current value of the editor is returned, setContentFromEditor() is called: 1 if the editMode() is Always
, or if editMode() is not Always
but the editor of the cell is active and the editor is not a QLineEdit.
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.
virtual QString QTableItem::text | ( | ) | const [virtual] |
bool QTableItem::wordWrap | ( | ) | const |
bool QTableItem::wordWrap | ( | ) | const |
Returns TRUE if word wrap is enabled for the cell; otherwise returns FALSE.
QTable [friend] |
static int QTableItem::RTTI = 0 [static] |
Reimplementado en QComboTableItem y QCheckTableItem.