QListWidget Class | Qt Widgets (2024)

Table of Contents
Member Function Documentation QListWidget::QListWidget(QWidget *parent = nullptr) [slot] void QListWidget::clear() [signal] void QListWidget::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) [signal] void QListWidget::currentRowChanged(int currentRow) [signal] void QListWidget::currentTextChanged(const QString &currentText) [signal] void QListWidget::itemActivated(QListWidgetItem *item) [signal] void QListWidget::itemChanged(QListWidgetItem *item) [signal] void QListWidget::itemClicked(QListWidgetItem *item) [signal] void QListWidget::itemDoubleClicked(QListWidgetItem *item) [signal] void QListWidget::itemEntered(QListWidgetItem *item) [signal] void QListWidget::itemPressed(QListWidgetItem *item) [signal] void QListWidget::itemSelectionChanged() [slot] void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible) [virtual] QListWidget::~QListWidget() void QListWidget::addItem(const QString &label) void QListWidget::addItem(QListWidgetItem *item) void QListWidget::addItems(const QStringList &labels) void QListWidget::closePersistentEditor(QListWidgetItem *item) QListWidgetItem *QListWidget::currentItem() const [override virtual protected] void QListWidget::dropEvent(QDropEvent *event) [virtual protected] bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action) void QListWidget::editItem(QListWidgetItem *item) [override virtual protected] bool QListWidget::event(QEvent *e) QList<QListWidgetItem *> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const QModelIndex QListWidget::indexFromItem(const QListWidgetItem *item) const void QListWidget::insertItem(int row, QListWidgetItem *item) void QListWidget::insertItem(int row, const QString &label) void QListWidget::insertItems(int row, const QStringList &labels) [since 5.10] bool QListWidget::isPersistentEditorOpen(QListWidgetItem *item) const QListWidgetItem *QListWidget::item(int row) const QListWidgetItem *QListWidget::itemAt(const QPoint &p) const QListWidgetItem *QListWidget::itemAt(int x, int y) const QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const QWidget *QListWidget::itemWidget(QListWidgetItem *item) const QList<QListWidgetItem *> QListWidget::items(const QMimeData *data) const [virtual protected] QMimeData *QListWidget::mimeData(const QList<QListWidgetItem *> &items) const [virtual protected] QStringList QListWidget::mimeTypes() const void QListWidget::openPersistentEditor(QListWidgetItem *item) void QListWidget::removeItemWidget(QListWidgetItem *item) int QListWidget::row(const QListWidgetItem *item) const QList<QListWidgetItem *> QListWidget::selectedItems() const void QListWidget::setCurrentItem(QListWidgetItem *item) void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command) void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) [override virtual] void QListWidget::setSelectionModel(QItemSelectionModel *selectionModel) void QListWidget::sortItems(Qt::SortOrder order = Qt::AscendingOrder) [virtual protected] Qt::DropActions QListWidget::supportedDropActions() const QListWidgetItem *QListWidget::takeItem(int row) QRect QListWidget::visualItemRect(const QListWidgetItem *item) const

Member Function Documentation

QListWidget::QListWidget(QWidget *parent = nullptr)

Constructs an empty QListWidget with the given parent.

[slot] void QListWidget::clear()

Removes all items and selections in the view.

Warning: All items will be permanently deleted.

[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::currentRowChanged(int currentRow)

This signal is emitted whenever the current item changes.

currentRow is the row of the current item. If there is no current item, the currentRow is -1.

Note: Notifier signal for property currentRow.

[signal] void QListWidget::currentTextChanged(const QString &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, the currentText is invalid.

[signal] void QListWidget::itemActivated(QListWidgetItem *item)

This signal is emitted when the item is activated. The item 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 the Return key, on Mac OS X it is Command+O).

[signal] void QListWidget::itemChanged(QListWidgetItem *item)

This signal is emitted whenever the data of item has changed.

[signal] void QListWidget::itemClicked(QListWidgetItem *item)

This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.

See also itemPressed() and itemDoubleClicked().

[signal] void QListWidget::itemDoubleClicked(QListWidgetItem *item)

This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.

See also itemClicked() and itemPressed().

[signal] void QListWidget::itemEntered(QListWidgetItem *item)

This signal is emitted when the mouse cursor enters an item. The item is the item entered. This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.

See also QWidget::setMouseTracking().

[signal] void QListWidget::itemPressed(QListWidgetItem *item)

This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.

See also itemClicked() and itemDoubleClicked().

[signal] void QListWidget::itemSelectionChanged()

This signal is emitted whenever the selection changes.

See also selectedItems(), QListWidgetItem::isSelected(), and currentItemChanged().

[slot] void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible)

Scrolls the view if necessary to ensure that the item is visible.

hint specifies where the item should be located after the operation.

[virtual] QListWidget::~QListWidget()

Destroys the list widget and all its items.

void QListWidget::addItem(const QString &label)

Inserts an item with the text label at the end of the list widget.

void QListWidget::addItem(QListWidgetItem *item)

Inserts the item at the end of the list widget.

Warning: A QListWidgetItem can only be added to a QListWidget once. Adding the same QListWidgetItem multiple times to a QListWidget will result in undefined behavior.

See also insertItem().

void QListWidget::addItems(const QStringList &labels)

Inserts items with the text labels at the end of the list widget.

See also insertItems().

void QListWidget::closePersistentEditor(QListWidgetItem *item)

Closes the persistent editor for the given item.

See also openPersistentEditor() and isPersistentEditorOpen().

QListWidgetItem *QListWidget::currentItem() const

Returns the current item.

See also setCurrentItem().

[override virtual protected] void QListWidget::dropEvent(QDropEvent *event)

Reimplements: QListView::dropEvent(QDropEvent *event).

[virtual protected] bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action)

Handles data supplied by an external drag and drop operation that ended with the given action in the given index. Returns true if data and action can be handled by the model; otherwise returns false.

See also supportedDropActions().

void QListWidget::editItem(QListWidgetItem *item)

Starts editing the item if it is editable.

[override virtual protected] bool QListWidget::event(QEvent *e)

Reimplements: QListView::event(QEvent *e).

QList<QListWidgetItem *> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const

Finds items with the text that matches the string text using the given flags.

QModelIndex QListWidget::indexFromItem(const QListWidgetItem *item) const

Returns the QModelIndex associated with the given item.

Note: In Qt versions prior to 5.10, this function took a non-const item.

void QListWidget::insertItem(int row, QListWidgetItem *item)

Inserts the item at the position in the list given by row.

See also addItem().

void QListWidget::insertItem(int row, const QString &label)

Inserts an item with the text label in the list widget at the position given by row.

See also addItem().

void QListWidget::insertItems(int row, const QStringList &labels)

Inserts items from the list of labels into the list, starting at the given row.

See also insertItem() and addItem().

[since 5.10] bool QListWidget::isPersistentEditorOpen(QListWidgetItem *item) const

Returns whether a persistent editor is open for item item.

This function was introduced in Qt 5.10.

See also openPersistentEditor() and closePersistentEditor().

QListWidgetItem *QListWidget::item(int row) const

Returns the item that occupies the given row in the list if one has been set; otherwise returns nullptr.

See also row().

QListWidgetItem *QListWidget::itemAt(const QPoint &p) const

Returns a pointer to the item at the coordinates p. The coordinates are relative to the list widget's viewport().

QListWidgetItem *QListWidget::itemAt(int x, int y) const

This is an overloaded function.

Returns a pointer to the item at the coordinates (x, y). The coordinates are relative to the list widget's viewport().

QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const

Returns a pointer to the QListWidgetItem associated with the given index.

QWidget *QListWidget::itemWidget(QListWidgetItem *item) const

Returns the widget displayed in the given item.

See also setItemWidget() and removeItemWidget().

QList<QListWidgetItem *> QListWidget::items(const QMimeData *data) const

Returns a list of pointers to the items contained in the data object. If the object was not created by a QListWidget in the same process, the list is empty.

[virtual protected] QMimeData *QListWidget::mimeData(const QList<QListWidgetItem *> &items) const

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.

If the list of items is empty, nullptr is returned instead of a serialized empty list.

[virtual protected] QStringList QListWidget::mimeTypes() const

Returns a list of MIME types that can be used to describe a list of listwidget items.

See also mimeData().

void QListWidget::openPersistentEditor(QListWidgetItem *item)

Opens an editor for the given item. The editor remains open after editing.

See also closePersistentEditor() and isPersistentEditorOpen().

void QListWidget::removeItemWidget(QListWidgetItem *item)

Removes the widget set on the given item.

To remove an item (row) from the list entirely, either delete the item or use takeItem().

See also itemWidget() and setItemWidget().

int QListWidget::row(const QListWidgetItem *item) const

Returns the row containing the given item.

See also item().

QList<QListWidgetItem *> QListWidget::selectedItems() const

Returns a list of all selected items in the list widget.

void QListWidget::setCurrentItem(QListWidgetItem *item)

Sets the current item to item.

Unless the selection mode is NoSelection, the item is also selected.

See also currentItem().

void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command)

Set the current item to item, using the given command.

void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)

Sets the current row to be the given row, using the given command,

Note: Setter function for property currentRow.

void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)

Sets the widget to be displayed in the given item.

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, use QListView and subclass QStyledItemDelegate instead.

See also itemWidget(), removeItemWidget(), and Delegate Classes.

[override virtual] void QListWidget::setSelectionModel(QItemSelectionModel *selectionModel)

Reimplements: QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel).

void QListWidget::sortItems(Qt::SortOrder order = Qt::AscendingOrder)

Sorts all the items in the list widget according to the specified order.

[virtual protected] Qt::DropActions QListWidget::supportedDropActions() const

Returns the drop actions supported by this view.

See also Qt::DropActions.

QListWidgetItem *QListWidget::takeItem(int row)

Removes and returns the item from the given row in the list widget; otherwise returns nullptr.

Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

See also insertItem() and addItem().

QRect QListWidget::visualItemRect(const QListWidgetItem *item) const

Returns the rectangle on the viewport occupied by the item at item.

QListWidget Class | Qt Widgets (2024)
Top Articles
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 5549

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.