
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQListWidget class provides an item-based list widget.More...
| Header: | #include <QListWidget> |
| Inherits: | QListView |
| QListWidget(QWidget * parent = 0) | |
| ~QListWidget() | |
| void | addItem(const QString & label) |
| void | addItem(QListWidgetItem * item) |
| void | addItems(const QStringList & labels) |
| void | closePersistentEditor(QListWidgetItem * item) |
| int | count() const |
| QListWidgetItem * | currentItem() const |
| int | currentRow() const |
| void | editItem(QListWidgetItem * item) |
| QList<QListWidgetItem *> | findItems(const QString & text, Qt::MatchFlags flags) const |
| void | insertItem(int row, QListWidgetItem * item) |
| void | insertItem(int row, const QString & label) |
| void | insertItems(int row, const QStringList & labels) |
| bool | isSortingEnabled() const |
| QListWidgetItem * | item(int row) const |
| QListWidgetItem * | itemAt(const QPoint & p) const |
| QListWidgetItem * | itemAt(int x, int y) const |
| QWidget * | itemWidget(QListWidgetItem * item) const |
| void | openPersistentEditor(QListWidgetItem * item) |
| void | removeItemWidget(QListWidgetItem * item) |
| int | row(const QListWidgetItem * item) const |
| QList<QListWidgetItem *> | selectedItems() const |
| void | setCurrentItem(QListWidgetItem * item) |
| void | setCurrentItem(QListWidgetItem * item, QItemSelectionModel::SelectionFlags command) |
| void | setCurrentRow(int row) |
| void | setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) |
| void | setItemWidget(QListWidgetItem * item, QWidget * widget) |
| void | setSortingEnabled(bool enable) |
| void | sortItems(Qt::SortOrder order = Qt::AscendingOrder) |
| QListWidgetItem * | takeItem(int row) |
| QRect | visualItemRect(const QListWidgetItem * item) const |
| virtual void | dropEvent(QDropEvent * event) |
| void | clear() |
| void | scrollToItem(const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible) |
| void | currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous) |
| void | currentRowChanged(int currentRow) |
| void | currentTextChanged(const QString & currentText) |
| void | itemActivated(QListWidgetItem * item) |
| void | itemChanged(QListWidgetItem * item) |
| void | itemClicked(QListWidgetItem * item) |
| void | itemDoubleClicked(QListWidgetItem * item) |
| void | itemEntered(QListWidgetItem * item) |
| void | itemPressed(QListWidgetItem * item) |
| void | itemSelectionChanged() |
| virtual bool | dropMimeData(int index, const QMimeData * data, Qt::DropAction action) |
| QModelIndex | indexFromItem(QListWidgetItem * item) const |
| QListWidgetItem * | itemFromIndex(const QModelIndex & index) const |
| QList<QListWidgetItem *> | items(const QMimeData * data) const |
| virtual QMimeData * | mimeData(const QList<QListWidgetItem *> items) const |
| virtual QStringList | mimeTypes() const |
| virtual Qt::DropActions | supportedDropActions() const |
| virtual bool | event(QEvent * e) |
TheQListWidget class provides an item-based list widget.
QListWidget is a convenience class that provides a list view similar to the one supplied byQListView, but with a classic item-based interface for adding and removing items.QListWidget uses an internal model to manage eachQListWidgetItem in the list.
For a more flexible list view widget, use theQListView class with a standard model.
List widgets are constructed in the same way as other widgets:
QListWidget *listWidget = new QListWidget(this);
TheselectionMode() 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 thesetSelectionMode() 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:
newQListWidgetItem(tr("Oak"), listWidget);newQListWidgetItem(tr("Fir"), listWidget);newQListWidgetItem(tr("Pine"), listWidget);
If you need to insert a new item into the list at a particular position, then it should be constructed without a parent widget. TheinsertItem() function should then be used to place it within the list. The list widget will take ownership of the item.
QListWidgetItem*newItem=newQListWidgetItem; 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 thecount() function. To remove items from the list, usetakeItem().
The current item in the list can be found withcurrentItem(), and changed withsetCurrentItem(). The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, thecurrentItemChanged() signal is emitted with the new current item and the item that was previously current.
![]() | ![]() | ![]() |
| AWindows XP style list widget. | AMacintosh style list widget. | APlastique style list widget. |
See alsoQListWidgetItem,QListView,QTreeView,Model/View Programming, andConfig Dialog Example.
This property holds the number of items in the list including any hidden items.
Access functions:
| int | count() const |
This property holds the row of the current item.
Depending on the current selection mode, the row may also be selected.
Access functions:
| int | currentRow() const |
| void | setCurrentRow(int row) |
| void | setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) |
Notifier signal:
| void | currentRowChanged(int currentRow) |
This property holds whether sorting is enabled.
If this property is true, sorting is enabled for the list; if the property is false, sorting is not enabled.
The default value is false.
This property was introduced in Qt 4.2.
Access functions:
| bool | isSortingEnabled() const |
| void | setSortingEnabled(bool enable) |
Constructs an emptyQListWidget with the givenparent.
Destroys the list widget and all its items.
Inserts an item with the textlabel at the end of the list widget.
Inserts theitem at the end of the list widget.
Warning: AQListWidgetItem can only be added to aQListWidget once. Adding the sameQListWidgetItem multiple times to aQListWidget will result in undefined behavior.
See alsoinsertItem().
Inserts items with the textlabels at the end of the list widget.
See alsoinsertItems().
[slot]void QListWidget::clear()Removes all items and selections in the view.
Warning: All items will be permanently deleted.
Closes the persistent editor for the givenitem.
See alsoopenPersistentEditor().
Returns the current item.
See alsosetCurrentItem().
[signal]void QListWidget::currentItemChanged(QListWidgetItem * current,QListWidgetItem * previous)This signal is emitted whenever the current item changes.
previous is the item that previously had the focus;current is the new current item.
[signal]void QListWidget::currentTextChanged(constQString & currentText)This signal is emitted whenever the current item changes.
currentText is the text data in the current item. If there is no current item, thecurrentText is invalid.
[virtual]void QListWidget::dropEvent(QDropEvent * event)Reimplemented fromQWidget::dropEvent().
[virtual protected]bool QListWidget::dropMimeData(int index, constQMimeData * data,Qt::DropAction action)Handlesdata supplied by an external drag and drop operation that ended with the givenaction in the givenindex. Returns true ifdata andaction can be handled by the model; otherwise returns false.
See alsosupportedDropActions().
Starts editing theitem if it is editable.
[virtual protected]bool QListWidget::event(QEvent * e)Reimplemented fromQObject::event().
Finds items with the text that matches the stringtext using the givenflags.
[protected]QModelIndex QListWidget::indexFromItem(QListWidgetItem * item) constReturns theQModelIndex assocated with the givenitem.
Inserts theitem at the position in the list given byrow.
See alsoaddItem().
Inserts an item with the textlabel in the list widget at the position given byrow.
See alsoaddItem().
Inserts items from the list oflabels into the list, starting at the givenrow.
See alsoinsertItem() andaddItem().
Returns the item that occupies the givenrow in the list if one has been set; otherwise returns 0.
See alsorow().
[signal]void QListWidget::itemActivated(QListWidgetItem * item)This signal is emitted when theitem is activated. Theitem is activated when the user clicks or double clicks on it, depending on the system configuration. It is also activated when the user presses the activation key (on Windows and X11 this is theReturn key, on Mac OS X it isCtrl+0).
Returns a pointer to the item at the coordinatesp. The coordinates are relative to the list widget'sviewport().
This is an overloaded function.
Returns a pointer to the item at the coordinates (x,y). The coordinates are relative to the list widget'sviewport().
[signal]void QListWidget::itemChanged(QListWidgetItem * item)This signal is emitted whenever the data ofitem has changed.
[signal]void QListWidget::itemClicked(QListWidgetItem * item)This signal is emitted with the specifieditem when a mouse button is clicked on an item in the widget.
See alsoitemPressed() anditemDoubleClicked().
[signal]void QListWidget::itemDoubleClicked(QListWidgetItem * item)This signal is emitted with the specifieditem when a mouse button is double clicked on an item in the widget.
See alsoitemClicked() anditemPressed().
[signal]void QListWidget::itemEntered(QListWidgetItem * item)This signal is emitted when the mouse cursor enters an item. Theitem is the item entered. This signal is only emitted whenmouseTracking is turned on, or when a mouse button is pressed while moving into an item.
See alsoQWidget::setMouseTracking().
[protected]QListWidgetItem * QListWidget::itemFromIndex(constQModelIndex & index) constReturns a pointer to theQListWidgetItem assocated with the givenindex.
[signal]void QListWidget::itemPressed(QListWidgetItem * item)This signal is emitted with the specifieditem when a mouse button is pressed on an item in the widget.
See alsoitemClicked() anditemDoubleClicked().
[signal]void QListWidget::itemSelectionChanged()This signal is emitted whenever the selection changes.
See alsoselectedItems(),QListWidgetItem::isSelected(), andcurrentItemChanged().
Returns the widget displayed in the givenitem.
This function was introduced in Qt 4.1.
See alsosetItemWidget().
[protected]QList<QListWidgetItem *> QListWidget::items(constQMimeData * data) constReturns a list of pointers to the items contained in thedata object. If the object was not created by aQListWidget in the same process, the list is empty.
[virtual protected]QMimeData * QListWidget::mimeData(constQList<QListWidgetItem *> items) constReturns an object that contains a serialized description of the specifieditems. The format used to describe the items is obtained from themimeTypes() function.
If the list of items is empty, 0 is returned instead of a serialized empty list.
[virtual protected]QStringList QListWidget::mimeTypes() constReturns a list of MIME types that can be used to describe a list of listwidget items.
See alsomimeData().
Opens an editor for the givenitem. The editor remains open after editing.
See alsoclosePersistentEditor().
Removes the widget set on the givenitem.
This function was introduced in Qt 4.3.
Returns the row containing the givenitem.
See alsoitem().
[slot]void QListWidget::scrollToItem(constQListWidgetItem * item,QAbstractItemView::ScrollHint hint = EnsureVisible)Scrolls the view if necessary to ensure that theitem is visible.
hint specifies where theitem should be located after the operation.
Returns a list of all selected items in the list widget.
Sets the current item toitem.
Unless the selection mode isNoSelection, the item is also be selected.
See alsocurrentItem().
Set the current item toitem, using the givencommand.
This function was introduced in Qt 4.4.
Sets thewidget to be displayed in the giveitem.
This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, useQListView and subclassQItemDelegate instead.
This function was introduced in Qt 4.1.
See alsoitemWidget() andDelegate Classes.
Sorts all the items in the list widget according to the specifiedorder.
[virtual protected]Qt::DropActions QListWidget::supportedDropActions() constReturns the drop actions supported by this view.
See alsoQt::DropActions.
Removes and returns the item from the givenrow in the list widget; otherwise returns 0.
Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.
See alsoinsertItem() andaddItem().
Returns the rectangle on the viewport occupied by the item atitem.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.