PySide6.QtWidgets.QListWidget¶
- class QListWidget¶
- The - QListWidgetclass provides an item-based list widget. More…- Synopsis¶- Properties¶- countᅟ- The number of items in the list including any hidden items
- currentRowᅟ- The row of the current item
- sortingEnabledᅟ- Whether sorting is enabled
 - Methods¶- def - __init__()
- def - addItem()
- def - addItems()
- def - count()
- def - currentItem()
- def - currentRow()
- def - editItem()
- def - findItems()
- def - indexFromItem()
- def - insertItem()
- def - insertItems()
- def - item()
- def - itemAt()
- def - itemFromIndex()
- def - itemWidget()
- def - items()
- def - row()
- def - selectedItems()
- def - setCurrentItem()
- def - setCurrentRow()
- def - setItemWidget()
- def - sortItems()
- def - takeItem()
- def - visualItemRect()
 - Virtual methods¶- def - dropMimeData()
- def - mimeData()
- def - mimeTypes()
 - Slots¶- def - clear()
- def - scrollToItem()
 - Signals¶
- def - itemActivated()
- def - itemChanged()
- def - itemClicked()
- def - itemEntered()
- def - itemPressed()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors.   - QListWidgetis 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.- QListWidgetuses an internal model to manage each- QListWidgetItemin the list.- For a more flexible list view widget, use the - QListViewclass with a standard model.- List widgets are constructed in the same way as other widgets: - listWidget = QListWidget(self) - 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: - QListWidgetItem(tr("Oak"), listWidget) QListWidgetItem(tr("Fir"), listWidget) QListWidgetItem(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. The - insertItem()function should then be used to place it within the list. The list widget will take ownership of the item.- newItem = 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- takeItem().- 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- currentItemChanged()signal is emitted with the new current item and the item that was previously current.- See also - QListWidgetItem- QListView- QTreeViewModel/View Programming Tab Dialog Example- Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property countᅟ: int¶
 - This property holds the number of items in the list including any hidden items.. - Access functions:
 - property currentRowᅟ: int¶
 - This property holds the row of the current item.. - Depending on the current selection mode, the row may also be selected. - Access functions:
 - property sortingEnabledᅟ: bool¶
 - 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. - Access functions:
 - Constructs an empty - QListWidgetwith the given- parent.- addItem(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - Inserts the - itemat the end of the list widget.- Warning - A - QListWidgetItemcan only be added to a- QListWidgetonce. Adding the same- QListWidgetItemmultiple times to a- QListWidgetwill result in undefined behavior.- See also - addItem(label)
- Parameters:
- label – str 
 
 - Inserts an item with the text - labelat the end of the list widget.- addItems(labels)¶
- Parameters:
- labels – list of strings 
 
 - Inserts items with the text - labelsat the end of the list widget.- See also - clear()¶
 - Removes all items and selections in the view. - Warning - All items will be permanently deleted. - closePersistentEditor(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - Closes the persistent editor for the given - item.- count()¶
- Return type:
- int 
 
 - Getter of property - countᅟ.- currentItem()¶
- Return type:
 
 - Returns the current item. - See also - currentItemChanged(current, previous)¶
- Parameters:
- current – - QListWidgetItem
- previous – - QListWidgetItem
 
 
 - This signal is emitted whenever the current item changes. - previousis the item that previously had the focus;- currentis the new current item.- currentRow()¶
- Return type:
- int 
 - See also 
 - Getter of property - currentRowᅟ.- currentRowChanged(currentRow)¶
- Parameters:
- currentRow – int 
 
 - This signal is emitted whenever the current item changes. - currentRowis the row of the current item. If there is no current item, the- currentRowis -1.- Notification signal of property - currentRowᅟ.- currentTextChanged(currentText)¶
- Parameters:
- currentText – str 
 
 - This signal is emitted whenever the current item changes. - currentTextis the text data in the current item. If there is no current item, the- currentTextis invalid.- dropMimeData(index, data, action)¶
- Parameters:
- index – int 
- data – - QMimeData
- action – - DropAction
 
- Return type:
- bool 
 
 - Handles - datasupplied by an external drag and drop operation that ended with the given- actionin the given- index. Returns- trueif- dataand- actioncan be handled by the model; otherwise returns- false.- See also - editItem(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - Starts editing the - itemif it is editable.- findItems(text, flags)¶
- Parameters:
- text – str 
- flags – Combination of - MatchFlag
 
- Return type:
- .list of list of WidgetItem 
 
 - Finds items with the text that matches the string - textusing the given- flags.- indexFromItem(item)¶
- Parameters:
- item – - QListWidgetItem
- Return type:
 
 - Returns the QModelIndex associated with the given - item.- Note - In Qt versions prior to 5.10, this function took a non- - const- item.- insertItem(row, item)¶
- Parameters:
- row – int 
- item – - QListWidgetItem
 
 
 - Inserts the - itemat the position in the list given by- row.- See also - insertItem(row, label)
- Parameters:
- row – int 
- label – str 
 
 
 - Inserts an item with the text - labelin the list widget at the position given by- row.- See also - insertItems(row, labels)¶
- Parameters:
- row – int 
- labels – list of strings 
 
 
 - Inserts items from the list of - labelsinto the list, starting at the given- row.- See also - isPersistentEditorOpen(item)¶
- Parameters:
- item – - QListWidgetItem
- Return type:
- bool 
 
 - Returns whether a persistent editor is open for item - item.- isSortingEnabled()¶
- Return type:
- bool 
 
 - Getter of property - sortingEnabledᅟ.- item(row)¶
- Parameters:
- row – int 
- Return type:
 
 - Returns the item that occupies the given - rowin the list if one has been set; otherwise returns- None.- See also - itemActivated(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted when the - itemis activated. The- itemis 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).- Returns a pointer to the item at the coordinates - p. The coordinates are relative to the list widget’s- viewport().- itemAt(x, y)
- Parameters:
- x – int 
- y – int 
 
- Return type:
 
 - 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().- itemChanged(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted whenever the data of - itemhas changed.- itemClicked(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted with the specified - itemwhen a mouse button is clicked on an item in the widget.- See also - itemDoubleClicked(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted with the specified - itemwhen a mouse button is double clicked on an item in the widget.- See also - itemEntered(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted when the mouse cursor enters an item. The - itemis 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 - itemFromIndex(index)¶
- Parameters:
- index – - QModelIndex
- Return type:
 
 - Returns a pointer to the - QListWidgetItemassociated with the given- index.- itemPressed(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - This signal is emitted with the specified - itemwhen a mouse button is pressed on an item in the widget.- See also - itemSelectionChanged()¶
 - This signal is emitted whenever the selection changes. - itemWidget(item)¶
- Parameters:
- item – - QListWidgetItem
- Return type:
 
 - Returns the widget displayed in the given - item.- See also - Returns a list of pointers to the items contained in the - dataobject. If the object was not created by a- QListWidgetin the same process, the list is empty.- 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, - Noneis returned instead of a serialized empty list.- mimeTypes()¶
- Return type:
- list of strings 
 
 - Returns a list of MIME types that can be used to describe a list of listwidget items. - See also - openPersistentEditor(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - Opens an editor for the given - item. The editor remains open after editing.- removeItemWidget(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - 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 - row(item)¶
- Parameters:
- item – - QListWidgetItem
- Return type:
- int 
 
 - Returns the row containing the given - item.- See also - scrollToItem(item[, hint=QAbstractItemView.ScrollHint.EnsureVisible])¶
- Parameters:
- item – - QListWidgetItem
- hint – - ScrollHint
 
 
 - Scrolls the view if necessary to ensure that the - itemis visible.- hintspecifies where the- itemshould be located after the operation.- selectedItems()¶
- Return type:
- .list of list of WidgetItem 
 
 - Returns a list of all selected items in the list widget. - setCurrentItem(item)¶
- Parameters:
- item – - QListWidgetItem
 
 - Sets the current item to - item.- Unless the selection mode is - NoSelection, the item is also selected.- See also - setCurrentItem(item, command)
- Parameters:
- item – - QListWidgetItem
- command – Combination of - SelectionFlag
 
 
 - Set the current item to - item, using the given- command.- setCurrentRow(row)¶
- Parameters:
- row – int 
 
 - Setter of property - currentRowᅟ.- setCurrentRow(row, command)
- Parameters:
- row – int 
- command – Combination of - SelectionFlag
 
 
 - Sets the current row to be the given - row, using the given- command,- See also - setItemWidget(item, widget)¶
- Parameters:
- item – - QListWidgetItem
- widget – - QWidget
 
 
 - Sets the - widgetto 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 - QListViewand subclass- QStyledItemDelegateinstead.- Note - The list takes ownership of the - widget.- setSortingEnabled(enable)¶
- Parameters:
- enable – bool 
 - See also 
 - Setter of property - sortingEnabledᅟ.- Sorts all the items in the list widget according to the specified - order.- supportedDropActions()¶
- Return type:
- Combination of - DropAction
 
 - Returns the drop actions supported by this view. - See also - DropActions- takeItem(row)¶
- Parameters:
- row – int 
- Return type:
 
 - Removes and returns the item from the given - rowin the list widget; otherwise returns- None.- Items removed from a list widget will not be managed by Qt, and will need to be deleted manually. - See also - visualItemRect(item)¶
- Parameters:
- item – - QListWidgetItem
- Return type:
 
 - Returns the rectangle on the viewport occupied by the item at - item.