summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqtableitem.3qt
blob: adc770799950e9a359aa26fbcee5697404cc5421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
'\" t
.TH QTableItem 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QTableItem \- The cell content for QTable cells
.SH SYNOPSIS
\fC#include <ntqtable.h>\fR
.PP
Inherits Qt.
.PP
Inherited by QComboTableItem and QCheckTableItem.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "enum \fBEditType\fR { Never, OnTyping, WhenCurrent, Always }"
.br
.ti -1c
.BI "\fBQTableItem\fR ( QTable * table, EditType et )"
.br
.ti -1c
.BI "\fBQTableItem\fR ( QTable * table, EditType et, const TQString & text )"
.br
.ti -1c
.BI "\fBQTableItem\fR ( QTable * table, EditType et, const TQString & text, const QPixmap & p )"
.br
.ti -1c
.BI "virtual \fB~QTableItem\fR ()"
.br
.ti -1c
.BI "virtual QPixmap \fBpixmap\fR () const"
.br
.ti -1c
.BI "virtual TQString \fBtext\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetPixmap\fR ( const QPixmap & p )"
.br
.ti -1c
.BI "virtual void \fBsetText\fR ( const TQString & str )"
.br
.ti -1c
.BI "QTable * \fBtable\fR () const"
.br
.ti -1c
.BI "virtual int \fBalignment\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetWordWrap\fR ( bool b )"
.br
.ti -1c
.BI "bool \fBwordWrap\fR () const"
.br
.ti -1c
.BI "EditType \fBeditType\fR () const"
.br
.ti -1c
.BI "virtual TQWidget * \fBcreateEditor\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetContentFromEditor\fR ( TQWidget * w )"
.br
.ti -1c
.BI "virtual void \fBsetReplaceable\fR ( bool b )"
.br
.ti -1c
.BI "bool \fBisReplaceable\fR () const"
.br
.ti -1c
.BI "virtual TQString \fBkey\fR () const"
.br
.ti -1c
.BI "virtual QSize \fBsizeHint\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetSpan\fR ( int rs, int cs )"
.br
.ti -1c
.BI "int \fBrowSpan\fR () const"
.br
.ti -1c
.BI "int \fBcolSpan\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetRow\fR ( int r )"
.br
.ti -1c
.BI "virtual void \fBsetCol\fR ( int c )"
.br
.ti -1c
.BI "int \fBrow\fR () const"
.br
.ti -1c
.BI "int \fBcol\fR () const"
.br
.ti -1c
.BI "virtual void \fBpaint\fR ( QPainter * p, const QColorGroup & cg, const QRect & cr, bool selected )"
.br
.ti -1c
.BI "virtual void \fBsetEnabled\fR ( bool b )"
.br
.ti -1c
.BI "bool \fBisEnabled\fR () const"
.br
.ti -1c
.BI "virtual int \fBrtti\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QTableItem class provides the cell content for QTable cells.
.PP
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.
.PP
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.
.PP
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.
.PP
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.
.PP
Example:
.PP
.nf
.br
    for ( int row = 0; row < table->numRows(); row++ ) {
.br
        for ( int col = 0; col < table->numCols(); col++ ) {
.br
            table->setItem( row, col,
.br
                new QTableItem( table, QTableItem::WhenCurrent, TQString::number( row * col ) ) );
.br
        }
.br
    }
.br
.fi
.PP
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().
.PP
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.
.PP
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.
.PP
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:
.PP
.nf
.br
    TQWidget* MyTableItem::createEditor() const
.br
    {
.br
        QHBox* hbox = new QHBox( table()->viewport() );
.br
        hbox->setFocusProxy(new QLineEdit( hbox ));
.br
        new QLineEdit( hbox );
.br
        return hbox;
.br
    }
.br
.fi
.PP
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.
.PP
<center>
.ce 1
.B "[Image Omitted]"
.PP
</center>
.PP
See also QCheckTableItem, QComboTableItem, and Advanced Widgets.
.PP
.SS "Member Type Documentation"
.SH "QTableItem::EditType"
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.
.TP
\fCQTableItem::Always\fR - The cell always \fIlooks\fR editable.
.PP
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.
.PP
If a cell with the edit type Always looks misaligned you could reimplement createEditor() for these items.
.TP
\fCQTableItem::WhenCurrent\fR - The cell \fIlooks\fR editable only when it has keyboard focus (see QTable::setCurrentCell()).
.TP
\fCQTableItem::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.
.PP
The OnTyping edit type is the default when QTableItem objects are created by the convenience functions QTable::setText() and QTable::setPixmap().
.TP
\fCQTableItem::Never\fR - The cell is not editable.
.PP
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.
.PP
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.
.PP
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QTableItem::QTableItem ( QTable * table, EditType et )"
Creates a table item that is a child of table \fItable\fR with no text. The item has the EditType \fIet\fR.
.PP
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().
.PP
The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.
.SH "QTableItem::QTableItem ( QTable * table, EditType et, const TQString & text )"
Creates a table item that is a child of table \fItable\fR with text \fItext\fR. The item has the EditType \fIet\fR.
.PP
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().
.PP
The table takes ownership of the table item, so a table item should not be inserted into more than one table at a time.
.SH "QTableItem::QTableItem ( QTable * table, EditType et, const TQString & text, const QPixmap & p )"
Creates a table item that is a child of table \fItable\fR with text \fItext\fR and pixmap \fIp\fR. The item has the EditType \fIet\fR.
.PP
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().
.PP
The table takes ownership of the table item, so a table item should not be inserted in more than one table at a time.
.SH "QTableItem::~QTableItem ()\fC [virtual]\fR"
The destructor deletes this item and frees all allocated resources.
.PP
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.
.SH "int QTableItem::alignment () const\fC [virtual]\fR"
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.
.PP
See also TQt::AlignmentFlags.
.SH "int QTableItem::col () const"
Returns the column where the table item is located. If the cell spans multiple columns, this function returns the left-most column.
.PP
See also row() and setCol().
.PP
Example: table/bigtable/main.cpp.
.SH "int QTableItem::colSpan () const"
Returns the column span of the table item, usually 1.
.PP
See also setSpan() and rowSpan().
.SH "TQWidget * QTableItem::createEditor () const\fC [virtual]\fR"
This virtual function creates an editor which the user can interact with to edit the cell's contents. The default implementation creates a QLineEdit.
.PP
If the function returns 0, the cell is read-only.
.PP
The returned widget should preferably be invisible, ideally with QTable::viewport() as parent.
.PP
If you reimplement this function you'll almost certainly need to reimplement setContentFromEditor(), and may need to reimplement sizeHint().
.PP
.nf
.br
    TQWidget *ComboItem::createEditor() const
.br
    {
.br
        // create an editor - a combobox in our case
.br
        ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() );
.br
        TQObject::connect( cb, SIGNAL( activated( int ) ), table(), SLOT( doValueChanged() ) );
.br
        cb->insertItem( "Yes" );
.br
        cb->insertItem( "No" );
.br
        // and initialize it
.br
        cb->setCurrentItem( text() == "No" ? 1 : 0 );
.br
        return cb;
.fi
.PP
See also QTable::createEditor(), setContentFromEditor(), QTable::viewport(), and setReplaceable().
.PP
Example: table/statistics/statistics.cpp.
.SH "EditType QTableItem::editType () const"
Returns the table item's edit type.
.PP
This is set when the table item is constructed.
.PP
See also EditType and QTableItem().
.SH "bool QTableItem::isEnabled () const"
Returns TRUE if the table item is enabled; otherwise returns FALSE.
.PP
See also setEnabled().
.SH "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.
.PP
(This differs from EditType because EditType is concerned with whether the \fIuser\fR is able to change the contents of a cell.)
.PP
See also setReplaceable() and EditType.
.SH "TQString QTableItem::key () const\fC [virtual]\fR"
This virtual function returns the key that should be used for sorting. The default implementation returns the text() of the relevant item.
.PP
See also QTable::sorting.
.SH "void QTableItem::paint ( QPainter * p, const QColorGroup & cg, const QRect & cr, bool selected )\fC [virtual]\fR"
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
.PP
.nf
.br
    p->setClipRect( table()->cellRect(row, col), QPainter::ClipPainter );
.br
    //... your drawing code
.br
    p->setClipping( FALSE );
.br
.fi
.PP
Example: table/statistics/statistics.cpp.
.SH "QPixmap QTableItem::pixmap () const\fC [virtual]\fR"
Returns the table item's pixmap or a null pixmap if no pixmap has been set.
.PP
See also setPixmap() and text().
.SH "int QTableItem::row () const"
Returns the row where the table item is located. If the cell spans multiple rows, this function returns the top-most row.
.PP
See also col() and setRow().
.PP
Example: table/bigtable/main.cpp.
.SH "int QTableItem::rowSpan () const"
Returns the row span of the table item, usually 1.
.PP
See also setSpan() and colSpan().
.SH "int QTableItem::rtti () const\fC [virtual]\fR"
Returns the Run Time Type Identification value for this table item which for QTableItems is 0.
.PP
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.
.PP
See also QCheckTableItem::rtti() and QComboTableItem::rtti().
.PP
Reimplemented in QComboTableItem and QCheckTableItem.
.SH "void QTableItem::setCol ( int c )\fC [virtual]\fR"
Sets column \fIc\fR as the table item's column. Usually you will not need to call this function.
.PP
If the cell spans multiple columns, this function sets the left-most column and retains the width of the multi-cell table item.
.PP
See also col(), setRow(), and colSpan().
.SH "void QTableItem::setContentFromEditor ( TQWidget * w )\fC [virtual]\fR"
Whenever the content of a cell has been edited by the editor \fIw\fR, QTable calls this virtual function to copy the new values into the QTableItem.
.PP
If you reimplement createEditor() and return something that is not a QLineEdit you will need to reimplement this function.
.PP
.nf
.br
    void ComboItem::setContentFromEditor( TQWidget *w )
.br
    {
.br
        // the user changed the value of the combobox, so synchronize the
.br
        // value of the item (its text), with the value of the combobox
.br
        if ( w->inherits( "QComboBox" ) )
.br
            setText( ( (QComboBox*)w )->currentText() );
.br
        else
.br
            QTableItem::setContentFromEditor( w );
.fi
.PP
See also QTable::setCellContentFromEditor().
.PP
Example: table/statistics/statistics.cpp.
.SH "void QTableItem::setEnabled ( bool b )\fC [virtual]\fR"
If \fIb\fR is TRUE, the table item is enabled; if \fIb\fR is FALSE the table item is disabled.
.PP
A disabled item doesn't respond to user interaction.
.PP
See also isEnabled().
.SH "void QTableItem::setPixmap ( const QPixmap & p )\fC [virtual]\fR"
Sets pixmap \fIp\fR to be this item's pixmap.
.PP
Note that setPixmap() does not update the cell the table item belongs to. Use QTable::updateCell() to repaint the cell's contents.
.PP
For QComboTableItems and QCheckTableItems this function has no visible effect.
.PP
See also QTable::setPixmap(), pixmap(), and setText().
.SH "void QTableItem::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 QTableItem. 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.
.PP
(This differs from EditType because EditType is concerned with whether the \fIuser\fR is able to change the contents of a cell.)
.PP
See also isReplaceable().
.SH "void QTableItem::setRow ( int r )\fC [virtual]\fR"
Sets row \fIr\fR as the table item's row. Usually you do not need to call this function.
.PP
If the cell spans multiple rows, this function sets the top row and retains the height of the multi-cell table item.
.PP
See also row(), setCol(), and rowSpan().
.SH "void QTableItem::setSpan ( int rs, int cs )\fC [virtual]\fR"
Changes the extent of the QTableItem so that it spans multiple cells covering \fIrs\fR rows and \fIcs\fR columns. The top left cell is the original cell.
.PP
\fBWarning:\fR This function only works if the item has already been inserted into the table using e.g. QTable::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 QTableItems spanning more than one cell is not supported.
.PP
See also rowSpan() and colSpan().
.SH "void QTableItem::setText ( const TQString & str )\fC [virtual]\fR"
Changes the table item's text to \fIstr\fR.
.PP
Note that setText() does not update the cell the table item belongs to. Use QTable::updateCell() to repaint the cell's contents.
.PP
See also QTable::setText(), text(), setPixmap(), and QTable::updateCell().
.PP
Example: table/statistics/statistics.cpp.
.SH "void QTableItem::setWordWrap ( bool b )\fC [virtual]\fR"
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.
.PP
See also wordWrap(), QTable::adjustColumn(), and QTable::setColumnStretchable().
.SH "QSize QTableItem::sizeHint () const\fC [virtual]\fR"
This virtual function returns the size a cell needs to show its entire content.
.PP
If you subclass QTableItem you will often need to reimplement this function.
.SH "QTable * QTableItem::table () const"
Returns the QTable the table item belongs to.
.PP
See also QTable::setItem() and QTableItem().
.SH "TQString QTableItem::text () const\fC [virtual]\fR"
Returns the text of the table item or TQString::null if there is no text.
.PP
To ensure that the current value of the editor is returned, setContentFromEditor() is called: <ol type=1>
.TP
if the editMode() is Always, or
.TP
if editMode() is \fInot\fR Always but the editor of the cell is active and the editor is not a QLineEdit.
.PP
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.
.PP
See also setText() and pixmap().
.SH "bool QTableItem::wordWrap () const"
Returns TRUE if word wrap is enabled for the cell; otherwise returns FALSE.
.PP
See also setWordWrap().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qtableitem.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt 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. 
.P
If you find errors in this manual page, please report them to
.BR [email protected] .
Please include the name of the manual page (tqtableitem.3qt) and the Qt
version (3.3.8).