Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QListWidget class provides an item-based list widget. More...
#include <QListWidget>
Inherits QListView.
The QListWidget class provides an item-based list widget.
QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list.
For a more flexible list view widget, use the QListView class with a standard model.
List widgets are constructed in the same way as other widgets:
QListWidget *listWidget;
The selectionMode() of a list widget determines how many of the items in the list can be selected at the same time, and whether complex selections of items can be created. This can be set with the setSelectionMode() function.
There are two ways to add items to the list: they can be constructed with the list widget as their parent widget, or they can be constructed with no parent widget and added to the list later. If a list widget already exists when the items are constructed, the first method is easier to use:
new QListWidgetItem(tr("Oak"), listWidget); new QListWidgetItem(tr("Fir"), listWidget); new QListWidgetItem(tr("Pine"), listWidget);
If you need to insert a new item into the list at a particular position, it is more convenient to construct the item without a parent widget and use the insertItem() function to place it within the list:
QListWidgetItem *newItem = new QListWidgetItem; newItem->setText(itemText); listWidget->insertItem(row, newItem);
For multiple items, insertItems() can be used instead. The number of items in the list is found with the count() function. To remove items from the list, use removeItem().
The current item in the list can be found with currentItem(), and changed with setCurrentItem(). The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, the currentChanged() signal is emitted with the new current item and the item that was previously current.
See also QListWidgetItem and Model/View Programming.
This property holds the number of items in the list including any hidden items.
Access functions:
Constructs an empty QListWidget with the given parent.
Destroys the list widget and all its items.
This signal is emitted when the widget is about to show a context menu. The menu is the menu about to be shown, and the item is the clicked item the context menu was called for.
See also QMenu::addAction().
Inserts the item at the the end of the list widget.
See also insertItem().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Inserts an item with the text label at the end of the list widget.
Inserts items with the text labels at the end of the list widget.
See also insertItems().
Removes all items and selections in the view.
Closes the persistent editor for the given item.
See also openPersistentEditor().
This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.
Returns the current item.
Scrolls the view if necessary to ensure that the item is visible.
Finds items that matches the text, using the criteria given in the flags (see QAbstractItemModel::MatchFlags).
Inserts the item at the position in the list given by row.
See also appendItem().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Inserts an item with the text label in the list widget at the position given by row.
See also appendItem().
Inserts items from the list of labels into the list, starting at the given row.
See also insertItem() and appendItem().
Returns true if the item is explicitly hidden; otherwise returns false.
Returns true if the item is in the viewport; otherwise returns false.
Returns true if item is selected and not hidden; otherwise returns false.
Returns the item that occupies the given row in the list.
See also row().
This signal is emitted whenever the data of item has changed.
Opens an editor for the given item. The editor remains open after editing.
See also closePersistentEditor().
This signal is emitted when return has been pressed on an item.
Returns the row containing the given item.
See also item().
Returns a list of all selected items in the list widget.
This signal is emitted whenever the selection changes.
See also selectedItems() and isSelected().
Sets the current item to item.
If hide is true, the item will be hidden; otherwise it will be shown.
Selects or deselects the given item depending on whether select is true of false.
Sorts all the items in the list widget according to the specified order.
Removes and returns the item from the given row in the list widget, otherwise return 0;
See also insertItem() and appendItem().
Copyright © 2004 Trolltech | Trademarks | Qt 4.0.0-b1 |