We've discarded the pointers to the items since we can still access them via their parent \fIlistView\fR. By default, TQListView sorts its items; this can be switched off with TQListView::setSorting(-1).
The parent must be another TQListViewItem or a TQListView. If the parent is a TQListView, the item becomes a top-level item within that TQListView. If the parent is another TQListViewItem, the item becomes a child of that list view item.
If you keep the pointer, you can set or change the texts using setText(), add pixmaps using setPixmap(), change its mode using setSelectable(), setSelected(), setOpen() and setExpandable(). You'll also be able to change its height using setHeight(), and traverse its sub-items. You don't have to keep the pointer since you can get a pointer to any TQListViewItem in a TQListView using TQListView::selectedItem(), TQListView::currentItem(), TQListView::firstChild(), TQListView::lastItem() and TQListView::findItem().
If you call \fCdelete\fR on a list view item, it will be deleted as expected, and as usual for TQObjects, if it has any child items (to any depth), all these will be deleted too.
You can traverse the tree as if it were a doubly-linked list using itemAbove() and itemBelow(); they return pointers to the items directly above and below this item on the screen (even if none of them are actually visible at the moment).
.PP
Here's how to traverse all of an item's children (but not its children's children, etc.): Example:
If you want to iterate over every item, to any level of depth use an iterator. To iterate over the entire tree, initialize the iterator with the list view itself; to iterate starting from a particular item, initialize the iterator with the item:
Note that the order of the children will change when the sorting order changes and is undefined if the items are not visible. You can, however, call enforceSortOrder() at any time; TQListView will always call it before it needs to show an item.
l - l. Function Description text() Returns the text in a column. Many subclasses will compute this on the fly. key() Used for sorting. The default key() simply calls text(), but judicious use of key() can give you fine control over sorting; for example, TQFileDialog reimplements key() to sort by date. setup() Called before showing the item and whenever the list view's font changes, for example. activate()
Some subclasses call setExpandable(TRUE) even when they have no children, and populate themselves when setup() or setOpen(TRUE) is called. The dirview/dirview.cpp example program uses this technique to start up quickly: The files and subdirectories in a directory aren't inserted into the tree until they're actually needed.
.SH "TQListViewItem::TQListViewItem ( TQListView * parent, TQListViewItem * after )"
Constructs an empty list view item that is a child of \fIparent\fR and is after item \fIafter\fR in the parent's list of children. Since \fIparent\fR is a TQListView the item will be a top-level item.
.SH "TQListViewItem::TQListViewItem ( TQListViewItem * parent, TQListViewItem * after )"
Constructs a new top-level list view item in the TQListView \fIparent\fR, with up to eight constant strings, \fIlabel1\fR, \fIlabel2\fR, \fIlabel3\fR, \fIlabel4\fR, \fIlabel5\fR, \fIlabel6\fR, \fIlabel7\fR and \fIlabel8\fR defining its columns' contents.
Constructs a new list view item as a child of the TQListViewItem \fIparent\fR with up to eight constant strings, \fIlabel1\fR, \fIlabel2\fR, \fIlabel3\fR, \fIlabel4\fR, \fIlabel5\fR, \fIlabel6\fR, \fIlabel7\fR and \fIlabel8\fR as columns' contents.
Constructs a new list view item in the TQListView \fIparent\fR that is included after item \fIafter\fR and that has up to eight column texts, \fIlabel1\fR, \fIlabel2\fR, \fIlabel3\fR, \fIlabel4\fR, \fIlabel5\fR, \fIlabel6\fR, \fIlabel7\fR and\fIlabel8\fR.
Constructs a new list view item as a child of the TQListViewItem \fIparent\fR. It is inserted after item \fIafter\fR and may contain up to eight strings, \fIlabel1\fR, \fIlabel2\fR, \fIlabel3\fR, \fIlabel4\fR, \fIlabel5\fR, \fIlabel6\fR, \fIlabel7\fR and \fIlabel8\fR as column entries.
When called from a reimplementation of activate(), this function gives information on how the item was activated. Otherwise the behavior is undefined.
.PP
If activate() was caused by a mouse press, the function sets \fIpos\fR to where the user clicked and returns TRUE; otherwise it returns FALSE and does not change \fIpos\fR.
.PP
\fIpos\fR is relative to the top-left corner of this item.
.PP
\fBWarning:\fR We recommend that you ignore this function; it is scheduled to become obsolete.
Compares this list view item to \fIi\fR using the column \fIcol\fR in \fIascending\fR order. Returns < 0 if this item is less than \fIi\fR, 0 if they are equal and > 0 if this item is greater than \fIi\fR.
The default implementation compares the item keys (key()) using TQString::localeAwareCompare(). A reimplementation can use different values and a different comparison function. Here is a reimplementation that uses plain Unicode comparison:
Note that the children are not guaranteed to be sorted properly. TQListView and TQListViewItem try to postpone or avoid sorting to the greatest degree possible, in order to keep the user interface snappy.
Inserts \fInewChild\fR into this list view item's list of children. You should not need to call this function; it is called automatically by the constructor of \fInewChild\fR.
.PP
\fBWarning:\fR If you are using \fCSingle\fR selection mode, then you should only insert unselected items.
Returns a pointer to the item immediately above this item on the screen. This is usually the item's closest older sibling, but it may also be its parent or its next older sibling's youngest child, or something else if anyoftheabove->height() returns 0. Returns 0 if there is no item immediately above this item.
.PP
This function assumes that all parents of this item are open (i.e. that this item is visible, or can be made visible by scrolling).
.PP
This function might be relatively slow because of the tree traversions needed to find the correct item.
Returns a pointer to the item immediately below this item on the screen. This is usually the item's eldest child, but it may also be its next younger sibling, its parent's next younger sibling, grandparent's, etc., or something else if anyoftheabove->height() returns 0. Returns 0 if there is no item immediately below this item.
.PP
This function assumes that all parents of this item are open (i.e. that this item is visible or can be made visible by scrolling).
Returns the y coordinate of this item in the list view's coordinate system. This function is normally much slower than TQListView::itemAt(), but it works for all items whereas TQListView::itemAt() normally only works for items on the screen.
Returns a key that can be used for sorting by column \fIcolumn\fR. The default implementation returns text(). Derived classes may also incorporate the order indicated by \fIascending\fR into this key, although this is not recommended.
.PP
If you want to sort on non-alphabetical data, e.g. dates, numbers, etc., it is more efficient to reimplement compare().
Note that this function traverses the items to the root to find the listview. This function will return 0 for taken items - see TQListViewItem::takeItem()
.SH "void TQListViewItem::moveItem ( TQListViewItem * after )"
Move the item to be after item \fIafter\fR, which must be one of the item's siblings. To move an item in the hierarchy, use takeItem() and insertItem().
.PP
Note that this function will have no effect if sorting is enabled in the list view.
Note that the siblings are not guaranteed to be sorted properly. TQListView and TQListViewItem try to postpone or avoid sorting to the greatest degree possible, in order to keep the user interface snappy.
Paints a set of branches from this item to (some of) its children.
.PP
Painter \fIp\fR is set up with clipping and translation so that you can only draw in the rectangle that needs redrawing; \fIcg\fR is the color group to use; the update rectangle is at (0, 0) and has size width \fIw\fR by height \fIh\fR. The top of the rectangle you own is at \fIy\fR (which is never greater than 0 but can be outside the window system's allowed coordinate range).
.PP
The update rectangle is in an undefined state when this function is called; this function must draw on \fIall\fR of the pixels.
\fIp\fR is a TQPainter open on the relevant paint device. \fIp\fR is translated so (0, 0) is the top-left pixel in the cell and \fIwidth-1\fR, height()-1 is the bottom-right pixel \fIin\fR the cell. The other properties of \fIp\fR (pen, brush, etc) are undefined. \fIcg\fR is the color group to use. \fIcolumn\fR is the logical column number within the item that is to be painted; 0 is the column which may contain a tree.
This function may use TQListView::itemMargin() for readability spacing on the left and right sides of data such as text, and should honor isSelected() and TQListView::allColumnsShowFocus().
If you reimplement this function, you should also reimplement width().
.PP
The rectangle to be painted is in an undefined state when this function is called, so you \fImust\fR draw on all the pixels. The painter \fIp\fR has the right font on entry.
Make your derived classes return their own values for rtti(), so that you can distinguish between different kinds of list view items. You should use values greater than 1000 to allow for extensions to this class.
If \fIb\fR is TRUE the item is enabled; otherwise it is disabled. Disabled items are drawn differently (e.g. grayed-out) and are not accessible by the user.
Sets this item to be expandable even if it has no children if \fIenable\fR is TRUE, and to be expandable only if it has children if \fIenable\fR is FALSE (the default).
.PP
The dirview example uses this in the canonical fashion. It checks whether the directory is empty in setup() and calls setExpandable(TRUE) if not; in setOpen() it reads the contents of the directory and inserts items accordingly. This strategy means that dirview can display the entire file system without reading very much at startup.
Opens or closes an item, i.e. shows or hides an item's children.
.PP
If \fIo\fR is TRUE all child items are shown initially. The user can hide them by clicking the \fB-\fR icon to the left of the item. If \fIo\fR is FALSE, the children of this item are initially hidden. The user can show them by clicking the \fB+\fR icon to the left of the item.
.PP
See also height(), totalHeight(), and isOpen().
.PP
Examples:
.)l checklists/checklists.cpp, dirview/dirview.cpp, dirview/main.cpp, fileiconview/mainwindow.cpp, and xml/tagreader-with-features/structureparser.cpp.
Sets the pixmap in column \fIcolumn\fR to \fIpm\fR, if \fIpm\fR is non-null and different from the current pixmap, and if \fIcolumn\fR is non-negative.
Sets this item to be selectable if \fIenable\fR is TRUE (the default) or not to be selectable if \fIenable\fR is FALSE.
.PP
The user is not able to select a non-selectable item using either the keyboard or the mouse. This also applies for the application programmer (e.g. setSelected() respects this value).
If the item is not visible, itemAbove() and itemBelow() will never return this item, although you still can reach it by using e.g. TQListViewItemIterator.
This virtual function is called before the first time TQListView needs to know the height or any other graphical attribute of this object, and whenever the font, GUI style, or colors of the list view change.
The default calls widthChanged() and sets the item's height to the height of a single line of text in the list view's font. (If you use icons, multi-line text, etc., you will probably need to call setHeight() yourself or reimplement it.)
Sorts this item's children using column \fIcolumn\fR. This is done in ascending order if \fIascending\fR is TRUE and in descending order if \fIascending\fR is FALSE.
Asks some of the children to sort their children. (TQListView and TQListViewItem ensure that all on-screen objects are properly sorted but may avoid or defer sorting other objects in order to be more responsive.)
If in-place renaming of this item is enabled (see renameEnabled()), this function starts renaming the item in column \fIcol\fR, by creating and initializing an edit box.
Removes \fIitem\fR from this object's list of children and causes an update of the screen display. The item is not deleted. You should not normally need to call this function because TQListViewItem::~TQListViewItem() calls it.
The normal way to delete an item is to use \fCdelete\fR.
.PP
If you need to move an item from one place in the hierarchy to another you can use takeItem() to remove the item from the list view and then insertItem() to put the item back in its new position.
.PP
If a taken item is part of a selection in \fCSingle\fR selection mode, it is unselected and selectionChanged() is emitted. If a taken item is part of a selection in \fCMulti\fR or \fCExtended\fR selection mode, it remains selected.
.PP
\fBWarning:\fR This function leaves \fIitem\fR and its children in a state where most member functions are unsafe. Only a few functions work correctly on an item in this state, most notably insertItem(). The functions that work on taken items are explicitly documented as such.
Returns the total height of this object, including any visible children. This height is recomputed lazily and cached for as long as possible.
.PP
Functions which can affect the total height are, setHeight() which is used to set an item's height, setOpen() to show or hide an item's children, and invalidateHeight() to invalidate the cached height.
.SH "int TQListViewItem::width ( const TQFontMetrics & fm, const TQListView * lv, int c ) const\fC [virtual]\fR"
Returns the number of pixels of width required to draw column \fIc\fR of list view \fIlv\fR, using the metrics \fIfm\fR without cropping. The list view containing this item may use this information depending on the TQListView::WidthMode settings for the column.
Call this function when the value of width() may have changed for column \fIc\fR. Normally, you should call this if text(c) changes. Passing -1 for \fIc\fR indicates that all columns may have changed. It is more efficient to pass -1 if two or more columns have changed than to call widthChanged() separately for each one.