The PySide.QtGui.QListWidget class provides an item-based list widget.
PySide.QtGui.QListWidget is a convenience class that provides a list view similar to the one supplied by PySide.QtGui.QListView , but with a classic item-based interface for adding and removing items. PySide.QtGui.QListWidget uses an internal model to manage each PySide.QtGui.QListWidgetItem in the list.
For a more flexible list view widget, use the PySide.QtGui.QListView class with a standard model.
List widgets are constructed in the same way as other widgets:
listWidget = QListWidget(self)The PySide.QtGui.QAbstractItemView.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 PySide.QtGui.QAbstractItemView.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, it is more required to construct the item without a parent widget and use the PySide.QtGui.QListWidget.insertItem() function 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, PySide.QtGui.QListWidget.insertItems() can be used instead. The number of items in the list is found with the PySide.QtGui.QListWidget.count() function. To remove items from the list, use PySide.QtGui.QListWidget.takeItem() .
The current item in the list can be found with PySide.QtGui.QListWidget.currentItem() , and changed with PySide.QtGui.QListWidget.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 PySide.QtGui.QListWidget.currentItemChanged() signal is emitted with the new current item and the item that was previously current.
A Windows XP style list widget. A Macintosh style list widget. A Plastique style list widget. See also
PySide.QtGui.QListWidgetItem PySide.QtGui.QListView PySide.QtGui.QTreeView Model/View Programming Config Dialog Example
Parameters: | parent – PySide.QtGui.QWidget |
---|
Constructs an empty PySide.QtGui.QListWidget with the given parent .
Parameters: | label – unicode |
---|
Inserts an item with the text label at the end of the list widget.
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Inserts the item at the end of the list widget.
Warning
A PySide.QtGui.QListWidgetItem can only be added to a PySide.QtGui.QListWidget once. Adding the same PySide.QtGui.QListWidgetItem multiple times to a PySide.QtGui.QListWidget will result in undefined behavior.
Parameters: | labels – list of strings |
---|
Inserts items with the text labels at the end of the list widget.
Removes all items and selections in the view.
Warning
All items will be permanently deleted.
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Closes the persistent editor for the given item .
Return type: | PySide.QtCore.int |
---|
This property holds the number of items in the list including any hidden items..
Return type: | PySide.QtGui.QListWidgetItem |
---|
Returns the current item.
Parameters: |
|
---|
Return type: | PySide.QtCore.int |
---|
This property holds the row of the current item..
Depending on the current selection mode, the row may also be selected.
Parameters: | currentRow – PySide.QtCore.int |
---|
Parameters: | currentText – unicode |
---|
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Starts editing the item if it is editable.
Parameters: |
|
---|---|
Return type: |
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|---|
Return type: | PySide.QtCore.QModelIndex |
Returns the PySide.QtCore.QModelIndex assocated with the given item .
Parameters: |
|
---|
Inserts an item with the text label in the list widget at the position given by row .
See also
Parameters: |
|
---|
Inserts the item at the position in the list given by row .
See also
Parameters: |
|
---|
Inserts items from the list of labels into the list, starting at the given row .
Return type: | PySide.QtCore.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.
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QListWidgetItem |
Returns the item that occupies the given row in the list if one has been set; otherwise returns 0.
See also
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: |
|
---|---|
Return type: |
This is an overloaded function.
Returns a pointer to the item at the coordinates (x , y ).
Parameters: | p – PySide.QtCore.QPoint |
---|---|
Return type: | PySide.QtGui.QListWidgetItem |
Returns a pointer to the item at the coordinates p .
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: | index – PySide.QtCore.QModelIndex |
---|---|
Return type: | PySide.QtGui.QListWidgetItem |
Returns a pointer to the PySide.QtGui.QListWidgetItem assocated with the given index .
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|---|
Return type: | PySide.QtGui.QWidget |
Returns the widget displayed in the given item .
Parameters: | data – PySide.QtCore.QMimeData |
---|---|
Return type: |
Returns a list of pointers to the items contained in the data object. If the object was not created by a PySide.QtGui.QListWidget in the same process, the list is empty.
Parameters: | items – |
---|---|
Return type: | PySide.QtCore.QMimeData |
Return type: | list of strings |
---|
Returns a list of MIME types that can be used to describe a list of listwidget items.
See also
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Opens an editor for the given item . The editor remains open after editing.
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Removes the widget set on the given item .
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|---|
Return type: | PySide.QtCore.int |
Returns the row containing the given item .
See also
Parameters: |
---|
Return type: |
---|
Returns a list of all selected items in the list widget.
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|
Sets the current item to item .
Unless the selection mode is NoSelection , the item is also be selected.
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: | row – PySide.QtCore.int |
---|
This property holds the row of the current item..
Depending on the current selection mode, the row may also be selected.
Parameters: |
|
---|
Sets the widget to be displayed in the give 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 PySide.QtGui.QListView and subclass PySide.QtGui.QItemDelegate instead.
See also
PySide.QtGui.QListWidget.itemWidget() Delegate Classes
Parameters: | enable – PySide.QtCore.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.
Parameters: | order – PySide.QtCore.Qt.SortOrder |
---|
Return type: | PySide.QtCore.Qt.SortOrder |
---|
Return type: | PySide.QtCore.Qt.DropActions |
---|
Returns the drop actions supported by this view.
See also
Qt.DropActions
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QListWidgetItem |
Removes and returns the item from the given row 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.
Parameters: | item – PySide.QtGui.QListWidgetItem |
---|---|
Return type: | PySide.QtCore.QRect |
Returns the rectangle on the viewport occupied by the item at item .