Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
The QListBox widget provides a list of selectable, read-only items. More...
#include <qlistbox.h>
Inherits QScrollView.
This is typically a single-column list where zero or one items are selected at once, but can also be used in many other ways.
QListBox will add scroll bars as necessary, but isn't intended for really big lists. If you want more than a few thousand items, it's probably better to use a different widget, chiefly because the scroll bars won't provide very good navigation, but also because QListBox may become slow at larger sizes.
There is a variety of selection modes, described in the QListBox::SelectionMode documentation. The default is single-selection, and you can change it using setSelectionMode(). For compatibility with previous Qt versions there is still the setMultiSelection() methode. Calling setMultiSelection( TRUE ) is equivalent to setSelectionMode( Multi ), and setMultiSelection( FALSE ) is equivalent to setSelectionMode( Single ). It's suggested not to use setMultiSelection() anymore, but to use setSelectionMode() instead.
Since QListBox offers multiple selection it has to display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item, setSelected(), and to select which item displays keyboard focus, setCurrentItem().
The list box normally arranges its items in a single column with a vertical scroll bar if necessary, but it is also possible to have a different fixed number of columns (setColumnMode()), or as many columns as will fit in the list box' 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' assigned screen space (setRowMode( FitToHeight )). In all these cases, QListBox will add scroll bars as appropriate in at least one direction.
If multiple rows is 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 ). Of course there is a similar setVariableWidth().
The items discussed are QListBoxItem objects. QListBox provides methods to insert new items as a string, 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 (surprise: removeItem()) and clear() the entire list box. Note that if you create a QListBoxItem yourself and insert it, it becomes the property of QListBox and you may not delete it. (QListBox will delete it when appropriate.)
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 listbox.
The list of items can be arbitrarily big; if necessary, QListBox adds scroll bars. It can be single-column (as most list boxes are) or multi-column, and offers both single and multiple selection. (QListBox does however not support multiple-column items; QListView does that job.) Also a listbox can display items arranged in a tree. But this is quite limited, and if you really want to display and work with a tree, you should use a QListView. The tree stuff in the QListBox is only supported because itīs needed in comboboxes.
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; most things can be done using the indexes too but unfortunately not everything.
Each item in a QListBox contains a QListBoxItem. One of the items can be the current item. The highlighted() signal is emitted when a new item gets highlighted, 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 return when an item is highlighted.
If the user does not select anything, no signals are emitted and currentItem() returns -1.
A list box has WheelFocus as a default focusPolicy(), i.e. it can get keyboard focus both by tabbing, clicking and the mouse wheel.
New items may be inserted using either insertItem(), insertStrList() or insertStringList(). inSort() is obsolete, as this method is quite inefficient. It's preferable to insert the items normally and call sort() afterwards, or insert a sorted QStringList().
By default, vertical and horizontal scroll bars are added and removed as necessary. setHScrollBarMode() and setVScrollBarMode() can be used to change this policy.
If you need to insert other types than texts and pixmaps, you must define new classes which inherit QListBoxItem.
Warning: The list box assumes ownership of all list box items and will delete them when it does not need them any more.
See also QListView, QComboBox, QButtonGroup, and GUI Design Handbook: List Box (two sections).
This enum type decides how QListBox lays out its rows and columns. The two modes interact, of course.
The possible values for each mode are:
Example: When you call setRowMode( FitToHeight ), columnMode() automatically becomes Variable to accomodate the row mode you've set.
This enumerated type is used by QListBox to indicate how it reacts to selection by the user. It has four values:
In other words, Single is a real single-selection list box, Multi a real multi-selection list box, and Extended list box where 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.
Performance is boosted by modifying the widget flags f so that only part of the QListBoxItem children is redrawn. This may be unsuitable for custom QListBoxItem classes, in which case WNorthWestGravity and WRepaintNoErase should be cleared.
See also QWidget::clearWFlags() and Qt::WidgetFlags.
See also QListBox::ensureCurrentVisible().
See also insertItem() and removeItem().
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
See also removeItem().
Note that a single-selection listbox will automatically select an item if it has keyboard focus.
This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listbox. item is the pointer to the clicked listbox item or NULL, if the user didn't click on an item.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listbox. item is the pointer to the clicked listbox item or NULL, if the user didn't click on an item. pnt is the position where the user has clicked.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
See also rowMode(), setColumnMode(), and numColumns().
This signal is emitted when the user highlights a new current item. The argument is the index of the new item, which is already current.
See also setCurrentItem() and currentItem().
See also topItem().
Returns the text of the current item.
This is equivalent to text(currentItem()).
This signal is emitted whenever an item is double-clicked. It's emitted on the second button press, not the second button release. item is the listbox item onto which the user did the double click.
This signal is emitted when the user highlights a new current item. The argument is the index of the new item, which is already current.
See also selected(), currentItem(), and selectionChanged().
This signal is emitted when the user highlights a new current item and the new item is a string. The argument is the text of the new current item.
See also selected(), currentItem(), and selectionChanged().
This signal is emitted when the user highlights a new current item. The argument is a pointer to the new current item.
See also selected(), currentItem(), and selectionChanged().
Using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards.
Inserts lbi at its sorted position in the list box.
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.
See also insertItem() and sort().
Using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards.
Inserts a new item of text at its sorted position in the list box.
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.
See also insertItem() and sort().
See also item().
If index is negative or larger than the number of items in the list box, lbi is inserted at the end of the list.
See also insertStrList().
If after is NULL, lbi is inserted at the beginning.
See also insertStrList().
If index is negative, text is inserted at the end of the list.
See also insertStrList().
If index is negative, pixmap is inserted at the end of the list.
See also insertStrList().
If index is negative, pixmap is inserted at the end of the list.
See also insertStrList().
If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.
Warning: This function uses const char * rather than
QString, 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() - it uses real QStrings.
Warning: This function is never significantly faster than a loop around insertItem().
See also insertItem() and insertStringList().
If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.
Warning: This function uses const char * rather than
QString, 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() - it uses real QStrings.
Warning: This function is never significantly faster than a loop around insertItem().
See also insertItem() and insertStringList().
If index is negative, insertStrList() inserts strings at the end of the list. If index is too large, the operation is ignored.
Warning: This function uses const char * rather than
QString, 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() - it uses real QStrings.
Warning: This function is never significantly faster than a loop around insertItem().
See also insertItem() and insertStringList().
If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.
Warning: This function is never significantly faster than a loop around insertItem().
See also insertItem() and insertStrList().
Consider using selectionMode() instead of this method.
Returns TRUE if the listbox is in multi-selection mode or extended selection mode, and FALSE if it is in single-selection mode or no-selection more.
See also selectionMode() and setSelectionMode().
See also index().
If index is too large, this function returns 0.
This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listbox. button is the mouse button, which the user pressed. item is the pointer to the clicked listbox item or NULL, if the user didn't click on an item. pos is the position where the user has clicked.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
This signal is emitted whenever the user presses the mouse button on a listbox. button is the mouse button, which the user pressed. item is the pointer to the listbox item onto which the user pressed the mouse button or NULL, if the user didn't press the mouse on an item. pos is the position of the mouse cursor where the mouse cursor was when the user pressed the mouse button.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
See also setColumnMode(), setRowMode(), and numRows().
See also setRowMode() and numColumns().
See also text().
This signal is emitted whenever the user presses the mouse button on a listbox. item is the pointer to the listbox item onto which the user pressed the mouse button or NULL, if the user didn't press the mouse on an item.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
This signal is emitted whenever the user presses the mouse button on a listbox. item is the pointer to the listbox item onto which the user pressed the mouse button or NULL, if the user didn't press the mouse on an item. pnt is the position of the mouse cursor where the mouse cursor was when the user pressed the mouse button.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
See also insertItem() and clear().
This signal is emitted when enter or return is pressed. The argument is currentItem().
This signal is emitted when the right button is clicked (ie. when it's released). The arguments are the relevant QListBoxItem (may be 0) and the point in global coordinates.
This signal is emitted when the right button is pressed. Then arguments are the relevant QListBoxItem (may be 0) and the point in global coordinates.
See also columnMode(), setRowMode(), and numRows().
This signal is emitted when the user double-clicks on an item or presses return when an item is highlighted. The argument is the index of the selected item.
See also highlighted() and selectionChanged().
This signal is emitted when the user double-clicks on an item or presses return while an item is highlighted, and the selected item is (or has) a string. The argument is the text of the selected item.
See also highlighted() and selectionChanged().
This signal is emitted when the user double-clicks on an item or presses return when an item is highlighted. The argument is a pointer to the new selected item.
See also highlighted() and selectionChanged().
This signal is emitted when the selection set of a listbox 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.
See also selected() and currentItem().
This signal is emitted when the selection in a single-selection listbox changes. item is the new selected listbox item.
See also selected() and currentItem().
See also setSelectionMode().
See also setTopItem().
The row layout mode implicitly becomes Variable.
If mode is Variable, this function returns without doing anything.
See also setRowMode() and columnMode().
See also setRowMode(), columnMode(), and numColumns().
See also currentItem().
This is a bit slower than the QListBoxItem * version.
Consider using setSelectionMode() instead of this method.
Sets the list box to multi-selection mode if enable is TRUE, and to single-selection mode if enable is FALSE. We recommend using setSelectionMode() instead; that function also offers two other modes.
See also setSelectionMode() and selectionMode().
The column layout mode implicitly becomes Variable.
If mode is Variable, this function returns without doing anything.
See also setColumnMode() and rowMode().
See also setColumnMode(), rowMode(), and numRows().
If the listbox is a single-selection listbox and and select is TRUE, setCurrentItem() is called.
If the listbox is a single-selection listbox and and select is FALSE, clearSelection() is called if item is the currently selected item.
Note that for this function, no-selection means multi-selection. The user cannot select items in a no-selection list box, but the application programmer can.
See also setMultiSelection(), setCurrentItem(), clearSelection(), and currentItem().
If the listbox is a single-selection listbox and and select is TRUE, setCurrentItem() will be called.
If the listbox is a single-selection listbox and and select is FALSE, clearSelection() will be called if index is the currently selected item.
See also setMultiSelection(), setCurrentItem(), clearSelection(), and currentItem().
See also selectionMode().
See also topItem() and ensureCurrentVisible().
When the list box has variable-height rows, 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.
The default is TRUE.
See also setVariableWidth() and variableHeight().
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, all columns are as wide as the widest item in the list box.
The default is FALSE.
See also setVariableHeight() and variableWidth().
To compare the items, the text (QListBoxItem::text()) of the items is used. The sorting is done using the Quick-Sort Alogorithm.
See also QListBox::insertItem().
See also pixmap().
See also setMultiSelection().
See also setVariableHeight() and setVariableWidth().
See also setVariableHeight() and setVariableWidth().
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|