The QListBox widget provides a list of selectable, read-only items. More...
#include <qlistbox.h>
Inherits QScrollView.
Type | Name | READ | WRITE | Options |
---|---|---|---|---|
uint | count | count | ||
int | numItemsVisible | numItemsVisible | ||
int | currentItem | currentItem | setCurrentItem | DESIGNABLE false |
QString | currentText | currentText | ||
int | topItem | topItem | setTopItem | DESIGNABLE false |
SelectionMode | selectionMode | selectionMode | setSelectionMode | |
bool | multiSelection | isMultiSelection | setMultiSelection | DESIGNABLE false |
LayoutMode | columnMode | columnMode | setColumnMode | |
LayoutMode | rowMode | rowMode | setRowMode | |
int | numColumns | numColumns | ||
int | numRows | numRows | ||
bool | variableWidth | variableWidth | setVariableWidth | |
bool | variableHeight | variableHeight | setVariableHeight |
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 is does not need them any more.
See also QListView, QComboBox, QButtonGroup and GUI Design Handbook: List Box (two sections)
The possible values for each mode are:
FixedNumber
- there is a fixed number of rows (or columns).
FitToHeight
- there are as many rows as will fit on-screen.
(Ditto with FitToWidth
and columns.)
Variable
- there are as many rows as are required by the
column mode. (Or as many columns as required by the row mode.)
Example: When you call setRowMode( FitToHeight ), columnMode()
automatically becomes Variable
to accomodate the row mode you've
set.
Single
- 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().
Multi
- When the user selects an item in the most ordinary
way, the selection status of that item is toggled and the other
items are left alone.
Extended
- When the user selects an item in the most
ordinary way, 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 stayes pressed.
NoSelection
- Items cannot be selected.
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.
Constructs a list box. The arguments are passed directly to the QScrollView constructor.
Destroys the list box. Deletes all list box items.
If there is a current item, the listbox is scrolled, so that this item is displayed centered.
See also QListBox::ensureCurrentVisible().
Replaces the item at position index with lbi. If index is negative or too large, changeItem() does nothing.
See also insertItem() and removeItem().
Replaces the item at position index with pixmap and text.
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
Replaces the item at position index with pixmap.
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
Replaces the item at position index with text.
The operation is ignored if index is out of range.
See also insertItem() and removeItem().
Deletes all items in the list.
See also removeItem().
[virtual slot]
Deselects all items, if possible.
Note that a single-selection listbox will automatically select an item if it has keyboard focus.
[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.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
[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.
Returns the column layout mode for this list box. This is
normally FixedNumber,
but can be changed by calling setColumnMode()
See also rowMode(), setColumnMode() and numColumns().
Returns the number of items in the list box.
[signal]
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().
Returns the index of the current (highlighted) item of the list box, or -1 if no item has been selected.
See also topItem().
Returns the text of the current item.
This is equivalent to text(currentItem()).
[protected]
This function does the hard layout work. You should never need to call it.
[signal]
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.
[virtual slot]
Ensures that the current item is visible.
Finds the first listbox item which starts with text and returns it, or returns 0 of no such item could be found. The search is done case-insensitive.
Returns the first item of this listbox.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
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().
[signal]
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().
[signal]
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().
Returns the index of lbi, or -1 if the item is not in this list box or lbi is a NULL-Pointer.
See also item().
Inserts the item lbi into the list after the item after.
If after is NULL, lbi is inserted at the beginning.
See also insertStrList().
Inserts the item lbi into the list at index.
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().
Inserts pixmap and text into the list at index.
If index is negative, pixmap is inserted at the end of the list.
See also insertStrList().
Inserts pixmap into the list at index.
If index is negative, pixmap is inserted at the end of the list.
See also insertStrList().
Inserts text into the list at index.
If index is negative, text is inserted at the end of the list.
See also insertStrList().
Inserts the string list list into the list at item index.
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().
Inserts the string list list into the list at item index.
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().
Inserts the numStrings strings of the array strings into the list at itemindex.
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().
Inserts the string list list into the list at item index.
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().
[slot]
Inverts the selection. Works only in Multi and Extended selection mode.
This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.
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().
[protected]
Returns whether the user is selecting items using a rubber rectangle.
Returns TRUE if item i is selected. Returns FALSE if it is not selected or if there is an error.
Returns TRUE if item i is selected. Returns FALSE if it is not selected or if there is an error.
Returns a pointer to the item at position index, or 0 if index is out of bounds.
See also index().
Returns a pointer to the item at p, which is in on-screen coordinates, or a null pointer if there is no item at p.
Returns the height in pixels of the item with index index. index defaults to 0.
If index is too large, this function returns 0.
Returns the rectangle on the screen item occupies in viewport()'s coordinates, or an invalid rectangle if i is a null pointer or is not currently visible.
Returns TRUE if item is at least partly visible, or else FALSE.
Returns TRUE if the item at position index is at least partly visible.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns the width of the largest item in the listbox.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
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.
[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.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Returns the number of columns in the list box. This is normally 1, but can be different if setColumnMode() or setRowMode() has been called.
See also setColumnMode(), setRowMode() and numRows().
Returns the number of visible items. Both partially and entirely visible items are counted.
Returns the number of rows in the list box. This is equal to the number of items in the default single-column layout, but can be different.
See also setRowMode() and numColumns().
[signal]
This signal is emitted, when the user moves the mouse cursor onto an item. It´s only emitted once per item.
[signal]
This signal is emitted, when the user moves the mouse cursor, which was on an item away from the item onto the viewport.
[virtual protected]
Provided for compatibility with the old QListBox. We recommend using QListBoxItem::paint().
Returns a pointer to the pixmap at position index, or 0 if there is no pixmap there.
See also text().
[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.
Note that you may not delete any QListBoxItem objects in slots connected to this signal.
[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.
Removes and deletes the item at position index. If index is equal to currentItem(), a new item gets highlighted and the highlighted() signal is emitted.
See also insertItem() and clear().
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[signal]
This signal is emitted when enter or return is pressed. The argument is currentItem().
[signal]
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.
[signal]
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.
Returns the row layout mode for this list box. This is normally
Variable,
but can be changed by calling setRowMode().
See also columnMode(), setRowMode() and numRows().
[slot]
If select is TRUE, all items get selected, else all get unselected. This works only in the selection modes Multi and Extended. In Single and NoSelection mode the selection of the current item is just set to select.
[signal]
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().
[signal]
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().
[signal]
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().
[signal]
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().
[signal]
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().
Returns the selection mode of the list box. The initial mode is Single.
See also setSelectionMode().
[virtual]
Scrolls the list box so the item at position index in the list is displayed in the bottom row of the list box.
See also setTopItem().
Sets the column layout mode to mode, and the number of displayed columns accordingly.
The row layout mode implicitly becomes Variable.
If mode is Variable,
this function returns without doing anything.
See also setRowMode() and columnMode().
[virtual]
Sets the column layout mode for this list box to FixedNumber,
and
sets the number of displayed columns accordingly.
See also setRowMode(), columnMode() and numColumns().
[virtual]
Sets the highlighted item to the item i. The highlighting is moved and the list box scrolled as necessary.
See also currentItem().
[virtual]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is a bit slower than the QListBoxItem * version.
[virtual]
Reimplemented for internal reasons; the API is not affected.
This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.
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().
Sets the row layout mode to mode, and the number of displayed rows accordingly.
The column layout mode implicitly becomes Variable.
If mode is Variable,
this function returns without doing anything.
See also setColumnMode() and rowMode().
[virtual]
Sets the row layout mode for this list box to FixedNumber
and sets the
number of displayed rows accordingly.
See also setColumnMode(), rowMode() and numRows().
[virtual]
Selects item if select is TRUE, or unselects it if select is FALSE, and repaints the item appropriately.
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 index 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().
Selects the item at position index if select is TRUE, or unselects it if select is FALSE, and repaints the item appropriately.
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().
Sets the list box to selection mode mode, which may be one of
Single
(the default), Extended, Multi
or NoSelection.
See also selectionMode().
[virtual]
Scrolls the list box so the item at position index in the list is displayed in the top row of the list box.
See also topItem() and ensureCurrentVisible().
[virtual]
Sets this list box to have variable-height rows if enable is TRUE, and equal-height rows if enable is FALSE.
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().
[virtual]
Sets this list box to have variable-width columns if enable is TRUE, and equal-width columns if enable is FALSE.
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().
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
Sorts the item in ascending order, if ascending is TRUE, or descending otherwise.
To compare the items, the text (QListBoxItem::text()) of the items is used. The sorting is done using the Quick-Sort Alogorithm.
Removes item from the listbox and causes an update of the screen
display. The item is not deleted. You should normally not need to
call this function, as QListBoxItem::~QListBoxItem() calls it. The
normal way to delete an item is delete.
See also QListBox::insertItem().
Returns the text at position index, or a null string if there is no text at that position.
See also pixmap().
[protected]
Toggles the selection status of currentItem() and repaints, if the listbox is a multi-selection listbox.
See also setMultiSelection().
Returns the index of an item at the top of the screen. If there are more than one of them, an arbitrary item is selected and returned.
Ensures that a single paint event will occur at the end of the current event loop iteration. If doLayout is TRUE, the layout is also redone.
[protected]
Repaints i.
[protected]
Repaints the item at position index in the list.
Returns TRUE if this list box has variable-height rows, and FALSE if all the rows have the same height.
See also setVariableHeight() and setVariableWidth().
Returns TRUE if this list box has variable-width columns, and FALSE if all the columns have the same width.
See also setVariableHeight() and setVariableWidth().
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QScrollView.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QScrollView.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QScrollView.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QScrollView.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QScrollView.
[protected slot]
For internal use only.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright © 2000 Trolltech | Trademarks | Qt version 2.2.1
|