.BI "bool itemYPos ( int index, int * yPos ) const \fI(obsolete)\fR"
.br
.ti -1c
.BI "int findItem ( int yPos ) const \fI(obsolete)\fR"
.br
.in -1c
.SH DESCRIPTION
The QListBox widget provides a list of selectable, read-only items.
.PP
This is typically a single-column list in which either no item or one item is selected, but it can also be used in many other ways.
.PP
QListBox will add scroll bars as necessary, but it isn't intended for \fIreally\fR big lists. If you want more than a few thousand items, it's probably better to use a different widget mainly because the scroll bars won't provide very good navigation, but also because QListBox may become slow with huge lists. (See QListView and QTable for possible alternatives.)
There are a variety of selection modes described in the QListBox::SelectionMode documentation. The default is Single selection mode, but you can change it using setSelectionMode(). (setMultiSelection() is still provided for compatibility with TQt 1.x. We recommend using setSelectionMode() in all code.)
Because QListBox offers multiple selection it must display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item, i.e. setSelected(), and to set which item displays keyboard focus, i.e. setCurrentItem().
The list box normally arranges its items in a single column and adds a vertical scroll bar if required. It is possible to have a different fixed number of columns (setColumnMode()), or as many columns as will fit in the list box's assigned screen space (setColumnMode(FitToWidth)), or to have a fixed number of rows (setRowMode()) or as many rows as will fit in the list box's assigned screen space (setRowMode(FitToHeight)). In all these cases QListBox will add scroll bars, as appropriate, in at least one direction.
If multiple rows are used, each row can be as high as necessary (the normal setting), or you can request that all items will have the same height by calling setVariableHeight(FALSE). The same applies to a column's width, see setVariableWidth().
.PP
The QListBox's items are QListBoxItem objects. QListBox provides methods to insert new items as strings, as pixmaps, and as QListBoxItem * (insertItem() with various arguments), and to replace an existing item with a new string, pixmap or QListBoxItem (changeItem() with various arguments). You can also remove items singly with removeItem() or clear() the entire list box. Note that if you create a QListBoxItem yourself and insert it, QListBox takes ownership of the item.
.PP
You can also create a QListBoxItem, such as QListBoxText or QListBoxPixmap, with the list box as first parameter. The item will then append itself. When you delete an item it is automatically removed from the list box.
.PP
The list of items can be arbitrarily large; QListBox will add scroll bars if necessary. QListBox can display a single-column (the common case) or multiple-columns, and offers both single and multiple selection. QListBox does not support multiple-column items (but QListView and QTable do), or tree hierarchies (but QListView does).
.PP
The list box items can be accessed both as QListBoxItem objects (recommended) and using integer indexes (the original QListBox implementation used an array of strings internally, and the API still supports this mode of operation). Everything can be done using the new objects, and most things can be done using indexes.
.PP
Each item in a QListBox contains a QListBoxItem. One of the items can be the current item. The currentChanged() signal and the highlighted() signal are emitted when a new item becomes current, e.g. because the user clicks on it or QListBox::setCurrentItem() is called. The selected() signal is emitted when the user double-clicks on an item or presses Enter on the current item.
.PP
If the user does not select anything, no signals are emitted and currentItem() returns -1.
.PP
A list box has WheelFocus as a default focusPolicy(), i.e. it can get keyboard focus by tabbing, clicking and through the use of the mouse wheel.
New items can be inserted using insertItem(), insertStrList() or insertStringList(). inSort() is obsolete because this method is quite inefficient. It's preferable to insert the items normally and call sort() afterwards, or to insert a sorted TQStringList().
By default, vertical and horizontal scroll bars are added and removed as necessary. setHScrollBarMode() and setVScrollBarMode() can be used to change this policy.
.PP
If you need to insert types other than strings and pixmaps, you must define new classes which inherit QListBoxItem.
.PP
\fBWarning:\fR The list box assumes ownership of all list box items and will delete them when it does not need them any more.
.PP
.ce 1
.B "[Image Omitted]"
.PP
.ce 1
.B "[Image Omitted]"
.PP
See also QListView, QComboBox, QButtonGroup, GUI Design Handbook: List Box (two sections), and Advanced Widgets.
.SS "Member Type Documentation"
.SH "QListBox::LayoutMode"
This enum type is used to specify how QListBox lays out its rows and columns.
.TP
\fCQListBox::FixedNumber\fR - There is a fixed number of rows (or columns).
.TP
\fCQListBox::FitToWidth\fR - There are as many columns as will fit on-screen.
.TP
\fCQListBox::FitToHeight\fR - There are as many rows as will fit on-screen.
Example: When you call setRowMode( FitToHeight ), columnMode() automatically becomes Variable to accommodate the row mode you've set.
.SH "QListBox::SelectionMode"
This enumerated type is used by QListBox to indicate how it reacts to selection by the user.
.TP
\fCQListBox::Single\fR - When the user selects an item, any already-selected item becomes unselected and the user cannot unselect the selected item. This means that the user can never clear the selection, even though the selection may be cleared by the application programmer using QListBox::clearSelection().
.TP
\fCQListBox::Multi\fR - When the user selects an item the selection status of that item is toggled and the other items are left alone. Also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
.TP
\fCQListBox::Extended\fR - When the user selects an item the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. And if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item get selected or unselected, depending on the state of the clicked item. Also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
.TP
\fCQListBox::NoSelection\fR - Items cannot be selected.
.PP
In other words, Single is a real single-selection list box, Multi is a real multi-selection list box, Extended is a list box in which users can select multiple items but usually want to select either just one or a range of contiguous items, and NoSelection is for a list box where the user can look but not touch.
Constructs a new empty list box called \fIname\fR and with parent \fIparent\fR.
.PP
Performance is boosted by modifying the widget flags \fIf\fR so that only part of the QListBoxItem children is redrawn. This may be unsuitable for custom QListBoxItem classes, in which case WStaticContents and WNoAutoErase should be cleared immediately after construction.
This signal is emitted when the user clicks any mouse button. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted when the user clicks any mouse button. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
\fIpnt\fR is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()). (If the click's press and release differs by a pixel or two, \fIpnt\fR is the position at release time.)
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
.SH "LayoutMode QListBox::columnMode () const"
Returns the column layout mode for this list box. See the "columnMode" property for details.
This signal is emitted when the user invokes a context menu with the right mouse button or with special system keys, with \fIitem\fR being the item under the mouse cursor or the current item, respectively.
.PP
\fIpos\fR is the position for the context menu in the global coordinate system.
.SH "uint QListBox::count () const"
Returns the number of items in the list box. See the "count" property for details.
This signal is emitted whenever an item is double-clicked. It's emitted on the second button press, not the second button release. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
Finds the first list box item that has the text \fItext\fR and returns it, or returns 0 of no such item could be found. The search starts from the current item if the current item exists, otherwise it starts from the first list box item. If \fCComparisonFlags\fR are specified in \fIcompare\fR then these flags are used, otherwise the default is a case-insensitive, "begins with" search.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted when the user makes a new item the current item and the item is (or has) a string. The argument is the text of the new current item.
.PP
See also currentChanged(), selected(), currentItem, and selectionChanged().
Inserts \fIlbi\fR at its sorted position in the list box and returns the position.
.PP
All items must be inserted with inSort() to maintain the sorting order. inSort() treats any pixmap (or user-defined type) as lexicographically less than any string.
Inserts a new item of \fItext\fR at its sorted position in the list box and returns the position.
.PP
All items must be inserted with inSort() to maintain the sorting order. inSort() treats any pixmap (or user-defined type) as lexicographically less than any string.
\fBWarning:\fR This function uses \fCconst char *\fR rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.
\fBWarning:\fR This function uses \fCconst char *\fR rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.
\fBWarning:\fR This function uses \fCconst char *\fR rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.
Returns the rectangle on the screen that \fIitem\fR occupies in viewport()'s coordinates, or an invalid rectangle if \fIitem\fR is 0 or is not currently visible.
.SH "bool QListBox::itemVisible ( int index )"
Returns TRUE if the item at position \fIindex\fR is at least partly visible; otherwise returns FALSE.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns TRUE if \fIitem\fR is at least partly visible; otherwise returns FALSE.
.SH "bool QListBox::itemYPos ( int index, int * yPos ) const\fC [protected]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Returns the vertical pixel-coordinate in \fI*yPos\fR, of the list box item at position \fIindex\fR in the list. Returns FALSE if the item is outside the visible area.
.SH "long QListBox::maxItemWidth () const"
Returns the width of the widest item in the list box.
This signal is emitted when the user clicks mouse button \fIbutton\fR. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
\fIpos\fR is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()). (If the click's press and release differs by a pixel or two, \fIpos\fR is the position at release time.)
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
This signal is emitted when the user presses mouse button \fIbutton\fR. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
\fIpos\fR is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()).
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
.SH "int QListBox::numCols () const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Returns the number of columns.
.PP
See also numColumns.
.SH "int QListBox::numColumns () const"
Returns the number of columns in the list box. See the "numColumns" property for details.
.SH "int QListBox::numItemsVisible () const"
Returns the number of visible items. See the "numItemsVisible" property for details.
.SH "int QListBox::numRows () const"
Returns the number of rows in the list box. See the "numRows" property for details.
.SH "void QListBox::onItem ( QListBoxItem * i )\fC [signal]\fR"
This signal is emitted when the user moves the mouse cursor onto an item, similar to the TQWidget::enterEvent() function. \fIi\fR is the QListBoxItem that the mouse has moved on.
This signal is emitted when the user presses any mouse button. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted when the user presses any mouse button. If \fIitem\fR is not 0, the cursor is on \fIitem\fR. If \fIitem\fR is 0, the mouse cursor isn't on any item.
.PP
\fIpnt\fR is the position of the mouse cursor in the global coordinate system (QMouseEvent::globalPos()).
.PP
Note that you must not delete any QListBoxItem objects in slots connected to this signal.
.PP
See also mouseButtonPressed(), rightButtonPressed(), and clicked().
.SH "void QListBox::removeItem ( int index )"
Removes and deletes the item at position \fIindex\fR. If \fIindex\fR is equal to currentItem(), a new item becomes current and the currentChanged() and highlighted() signals are emitted.
This signal is emitted when the right button is clicked (i.e. when it's released at the same point where it was pressed). The arguments are the relevant QListBoxItem (may be 0) and the point in global coordinates.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted when the user double-clicks on an item or presses Enter on the current item, and the item is (or has) a string. The argument is the text of the selected item.
.PP
See also currentChanged(), highlighted(), and selectionChanged().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This signal is emitted when the user double-clicks on an item or presses Enter on the current item. The argument is a pointer to the new selected item.
.PP
See also currentChanged(), highlighted(), and selectionChanged().
This signal is emitted when the selection set of a list box changes. This signal is emitted in each selection mode. If the user selects five items by drag-selecting, QListBox tries to emit just one selectionChanged() signal so the signal can be connected to computationally expensive slots.
Removes \fIitem\fR from the list box and causes an update of the screen display. The item is not deleted. You should normally not need to call this function because QListBoxItem::~QListBoxItem() calls it. The normal way to delete an item is with \fCdelete\fR.
Ensures that a single paint event will occur at the end of the current event loop iteration. If \fIdoLayout\fR is TRUE, the layout is also redone.
.SH "void QListBox::updateItem ( int index )\fC [protected]\fR"
Repaints the item at position \fIindex\fR in the list.
.SH "void QListBox::updateItem ( QListBoxItem * i )\fC [protected]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Repaints the QListBoxItem \fIi\fR.
.SH "bool QListBox::variableHeight () const"
Returns TRUE if this list box has variable-height rows; otherwise returns FALSE. See the "variableHeight" property for details.
.SH "bool QListBox::variableWidth () const"
Returns TRUE if this list box has variable-width columns; otherwise returns FALSE. See the "variableWidth" property for details.
.SS "Property Documentation"
.SH "LayoutMode columnMode"
This property holds the column layout mode for this list box.
.PP
setColumnMode() sets the layout mode and adjusts the number of displayed columns. The row layout mode automatically becomes Variable, unless the column mode is Variable.
.PP
See also rowMode, rowMode, and numColumns.
.PP
Set this property's value with setColumnMode() and get this property's value with columnMode().
.SH "uint count"
This property holds the number of items in the list box.
.PP
Get this property's value with count().
.SH "int currentItem"
This property holds the current highlighted item.
.PP
When setting this property, the highlighting is moved to the item and the list box scrolled as necessary.
.PP
If no item is current, currentItem() returns -1.
.PP
Set this property's value with setCurrentItem() and get this property's value with currentItem().
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
This property holds whether or not the list box is in Multi selection mode.
.PP
Consider using the QListBox::selectionMode property instead of this property.
.PP
When setting this property, Multi selection mode is used if set to TRUE and to Single selection mode if set to FALSE.
.PP
When getting this property, TRUE is returned if the list box is in Multi selection mode or Extended selection mode, and FALSE if it is in Single selection mode or NoSelection mode.
.PP
See also selectionMode.
.PP
Set this property's value with setMultiSelection() and get this property's value with isMultiSelection().
.SH "int numColumns"
This property holds the number of columns in the list box.
.PP
This is normally 1, but can be different if QListBox::columnMode or QListBox::rowMode has been set.
.PP
See also columnMode, rowMode, and numRows.
.PP
Get this property's value with numColumns().
.SH "int numItemsVisible"
This property holds the number of visible items.
.PP
Both partially and entirely visible items are counted.
.PP
Get this property's value with numItemsVisible().
.SH "int numRows"
This property holds the number of rows in the list box.
.PP
This is equal to the number of items in the default single-column layout, but can be different.
.PP
See also columnMode, rowMode, and numColumns.
.PP
Get this property's value with numRows().
.SH "LayoutMode rowMode"
This property holds the row layout mode for this list box.
.PP
This property is normally Variable.
.PP
setRowMode() sets the layout mode and adjusts the number of displayed rows. The column layout mode automatically becomes Variable, unless the row mode is Variable.
.PP
See also columnMode.
.PP
Set this property's value with setRowMode() and get this property's value with rowMode().
.SH "SelectionMode selectionMode"
This property holds the selection mode of the list box.
.PP
Sets the list box's selection mode, which may be one of Single (the default), Extended, Multi or NoSelection.
.PP
See also SelectionMode.
.PP
Set this property's value with setSelectionMode() and get this property's value with selectionMode().
.SH "int topItem"
This property holds the index of an item at the top of the screen.
.PP
When getting this property and the listbox has multiple columns, an arbitrary item is selected and returned.
.PP
When setting this property, the list box is scrolled so the item at position \fIindex\fR in the list is displayed in the top row of the list box.
.PP
Set this property's value with setTopItem() and get this property's value with topItem().
.SH "bool variableHeight"
This property holds whether this list box has variable-height rows.
.PP
When the list box has variable-height rows (the default), each row is as high as the highest item in that row. When it has same-sized rows, all rows are as high as the highest item in the list box.
.PP
See also variableWidth.
.PP
Set this property's value with setVariableHeight() and get this property's value with variableHeight().
.SH "bool variableWidth"
This property holds whether this list box has variable-width columns.
.PP
When the list box has variable-width columns, each column is as wide as the widest item in that column. When it has same-sized columns (the default), all columns are as wide as the widest item in the list box.
.PP
See also variableHeight.
.PP
Set this property's value with setVariableWidth() and get this property's value with variableWidth().