QListWidget¶
The
QListWidget
class provides an item-based list widget. More…
Synopsis¶
Functions¶
def
addItem
(item)def
addItem
(label)def
addItems
(labels)def
closePersistentEditor
(item)def
count
()def
currentItem
()def
currentRow
()def
editItem
(item)def
findItems
(text, flags)def
indexFromItem
(item)def
indexFromItem
(item)def
insertItem
(row, item)def
insertItem
(row, label)def
insertItems
(row, labels)def
isItemHidden
(item)def
isItemSelected
(item)def
isPersistentEditorOpen
(item)def
isSortingEnabled
()def
item
(row)def
itemAt
(p)def
itemAt
(x, y)def
itemFromIndex
(index)def
itemWidget
(item)def
items
(data)def
openPersistentEditor
(item)def
removeItemWidget
(item)def
row
(item)def
selectedItems
()def
setCurrentItem
(item)def
setCurrentItem
(item, command)def
setCurrentRow
(row)def
setCurrentRow
(row, command)def
setItemHidden
(item, hide)def
setItemSelected
(item, select)def
setItemWidget
(item, widget)def
setSortingEnabled
(enable)def
sortItems
([order=Qt.AscendingOrder])def
takeItem
(row)def
visualItemRect
(item)
Virtual functions¶
def
dropMimeData
(index, data, action)def
mimeData
(items)def
mimeTypes
()def
supportedDropActions
()
Slots¶
def
clear
()def
scrollToItem
(item[, hint=EnsureVisible])
Signals¶
def
currentItemChanged
(current, previous)def
currentRowChanged
(currentRow)def
currentTextChanged
(currentText)def
itemActivated
(item)def
itemChanged
(item)def
itemClicked
(item)def
itemDoubleClicked
(item)def
itemEntered
(item)def
itemPressed
(item)def
itemSelectionChanged
()
Detailed Description¶
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 the
QListView
class 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 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:
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 thecount()
function. To remove items from the list, usetakeItem()
.The current item in the list can be found with
currentItem()
, 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.
-
class
QListWidget
([parent=None])¶ - param parent
Constructs an empty
QListWidget
with the givenparent
.
-
PySide2.QtWidgets.QListWidget.
addItem
(item)¶ - Parameters
item –
QListWidgetItem
Inserts the
item
at the end of the list widget.Warning
A
QListWidgetItem
can only be added to aQListWidget
once. Adding the sameQListWidgetItem
multiple times to aQListWidget
will result in undefined behavior.See also
-
PySide2.QtWidgets.QListWidget.
addItem
(label) - Parameters
label – unicode
-
PySide2.QtWidgets.QListWidget.
addItems
(labels)¶ - Parameters
labels – list of strings
Inserts items with the text
labels
at the end of the list widget.See also
-
PySide2.QtWidgets.QListWidget.
clear
()¶ Removes all items and selections in the view.
Warning
All items will be permanently deleted.
-
PySide2.QtWidgets.QListWidget.
closePersistentEditor
(item)¶ - Parameters
item –
QListWidgetItem
Closes the persistent editor for the given
item
.
-
PySide2.QtWidgets.QListWidget.
count
()¶ - Return type
int
-
PySide2.QtWidgets.QListWidget.
currentItem
()¶ - Return type
Returns the current item.
See also
-
PySide2.QtWidgets.QListWidget.
currentItemChanged
(current, previous)¶ - Parameters
current –
QListWidgetItem
previous –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
currentRow
()¶ - Return type
int
See also
-
PySide2.QtWidgets.QListWidget.
currentRowChanged
(currentRow)¶ - Parameters
currentRow –
int
-
PySide2.QtWidgets.QListWidget.
currentTextChanged
(currentText)¶ - Parameters
currentText – unicode
-
PySide2.QtWidgets.QListWidget.
dropMimeData
(index, data, action)¶ - Parameters
index –
int
data –
QMimeData
action –
DropAction
- Return type
bool
Handles
data
supplied by an external drag and drop operation that ended with the givenaction
in the givenindex
. Returnstrue
ifdata
andaction
can be handled by the model; otherwise returnsfalse
.See also
-
PySide2.QtWidgets.QListWidget.
editItem
(item)¶ - Parameters
item –
QListWidgetItem
Starts editing the
item
if it is editable.
-
PySide2.QtWidgets.QListWidget.
findItems
(text, flags)¶ - Parameters
text – unicode
flags –
MatchFlags
- Return type
Finds items with the text that matches the string
text
using the givenflags
.
-
PySide2.QtWidgets.QListWidget.
indexFromItem
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
QModelIndex
This is an overloaded function.
-
PySide2.QtWidgets.QListWidget.
indexFromItem
(item) - Parameters
item –
QListWidgetItem
- Return type
QModelIndex
Returns the
QModelIndex
associated with the givenitem
.Note
In Qt versions prior to 5.10, this function took a non-
const
item
.
-
PySide2.QtWidgets.QListWidget.
insertItem
(row, label)¶ - Parameters
row –
int
label – unicode
-
PySide2.QtWidgets.QListWidget.
insertItem
(row, item) - Parameters
row –
int
item –
QListWidgetItem
Inserts the
item
at the position in the list given byrow
.See also
-
PySide2.QtWidgets.QListWidget.
insertItems
(row, labels)¶ - Parameters
row –
int
labels – list of strings
Inserts items from the list of
labels
into the list, starting at the givenrow
.See also
-
PySide2.QtWidgets.QListWidget.
isItemHidden
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
bool
Returns
true
if theitem
is explicitly hidden; otherwise returnsfalse
.This function is deprecated. Use
isHidden()
instead.
-
PySide2.QtWidgets.QListWidget.
isItemSelected
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
bool
Returns
true
ifitem
is selected; otherwise returnsfalse
.This function is deprecated. Use
isSelected()
instead.
-
PySide2.QtWidgets.QListWidget.
isPersistentEditorOpen
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
bool
Returns whether a persistent editor is open for item
item
.
-
PySide2.QtWidgets.QListWidget.
isSortingEnabled
()¶ - Return type
bool
-
PySide2.QtWidgets.QListWidget.
item
(row)¶ - Parameters
row –
int
- Return type
Returns the item that occupies the given
row
in the list if one has been set; otherwise returnsNone
.See also
-
PySide2.QtWidgets.QListWidget.
itemActivated
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
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’sviewport()
.
-
PySide2.QtWidgets.QListWidget.
itemAt
(p) - Parameters
p –
QPoint
- Return type
Returns a pointer to the item at the coordinates
p
. The coordinates are relative to the list widget’sviewport()
.
-
PySide2.QtWidgets.QListWidget.
itemChanged
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
itemClicked
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
itemDoubleClicked
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
itemEntered
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
itemFromIndex
(index)¶ - Parameters
index –
QModelIndex
- Return type
Returns a pointer to the
QListWidgetItem
associated with the givenindex
.
-
PySide2.QtWidgets.QListWidget.
itemPressed
(item)¶ - Parameters
item –
QListWidgetItem
-
PySide2.QtWidgets.QListWidget.
itemSelectionChanged
()¶
-
PySide2.QtWidgets.QListWidget.
itemWidget
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
Returns the widget displayed in the given
item
.See also
-
PySide2.QtWidgets.QListWidget.
items
(data)¶ - Parameters
data –
QMimeData
- Return type
Returns a list of pointers to the items contained in the
data
object. If the object was not created by aQListWidget
in the same process, the list is empty.
-
PySide2.QtWidgets.QListWidget.
mimeData
(items)¶ - Parameters
items –
- Return type
QMimeData
Returns an object that contains a serialized description of the specified
items
. 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.
-
PySide2.QtWidgets.QListWidget.
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
-
PySide2.QtWidgets.QListWidget.
openPersistentEditor
(item)¶ - Parameters
item –
QListWidgetItem
Opens an editor for the given
item
. The editor remains open after editing.
-
PySide2.QtWidgets.QListWidget.
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
-
PySide2.QtWidgets.QListWidget.
row
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
int
Returns the row containing the given
item
.See also
-
PySide2.QtWidgets.QListWidget.
scrollToItem
(item[, hint=EnsureVisible])¶ - Parameters
item –
QListWidgetItem
hint –
ScrollHint
Scrolls the view if necessary to ensure that the
item
is visible.hint
specifies where theitem
should be located after the operation.
-
PySide2.QtWidgets.QListWidget.
selectedItems
()¶ - Return type
Returns a list of all selected items in the list widget.
-
PySide2.QtWidgets.QListWidget.
setCurrentItem
(item)¶ - Parameters
item –
QListWidgetItem
Sets the current item to
item
.Unless the selection mode is
NoSelection
, the item is also selected.See also
-
PySide2.QtWidgets.QListWidget.
setCurrentItem
(item, command) - Parameters
item –
QListWidgetItem
command –
SelectionFlags
Set the current item to
item
, using the givencommand
.
-
PySide2.QtWidgets.QListWidget.
setCurrentRow
(row)¶ - Parameters
row –
int
See also
-
PySide2.QtWidgets.QListWidget.
setCurrentRow
(row, command) - Parameters
row –
int
command –
SelectionFlags
Sets the current row to be the given
row
, using the givencommand
,
-
PySide2.QtWidgets.QListWidget.
setItemHidden
(item, hide)¶ - Parameters
item –
QListWidgetItem
hide –
bool
If
hide
is true, theitem
will be hidden; otherwise it will be shown.This function is deprecated. Use
setHidden()
instead.See also
-
PySide2.QtWidgets.QListWidget.
setItemSelected
(item, select)¶ - Parameters
item –
QListWidgetItem
select –
bool
Selects or deselects the given
item
depending on whetherselect
is true of false.This function is deprecated. Use
setSelected()
instead.See also
-
PySide2.QtWidgets.QListWidget.
setItemWidget
(item, widget)¶ - Parameters
item –
QListWidgetItem
widget –
QWidget
Sets the
widget
to be displayed in the givenitem
.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 subclassQItemDelegate
instead.
-
PySide2.QtWidgets.QListWidget.
setSortingEnabled
(enable)¶ - Parameters
enable –
bool
See also
-
PySide2.QtWidgets.QListWidget.
sortItems
([order=Qt.AscendingOrder])¶ - Parameters
order –
SortOrder
Sorts all the items in the list widget according to the specified
order
.
-
PySide2.QtWidgets.QListWidget.
supportedDropActions
()¶ - Return type
DropActions
Returns the drop actions supported by this view.
See also
DropActions
-
PySide2.QtWidgets.QListWidget.
takeItem
(row)¶ - Parameters
row –
int
- Return type
Removes and returns the item from the given
row
in the list widget; otherwise returnsNone
.Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.
See also
-
PySide2.QtWidgets.QListWidget.
visualItemRect
(item)¶ - Parameters
item –
QListWidgetItem
- Return type
QRect
Returns the rectangle on the viewport occupied by the item at
item
.
© 2018 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 the GNU 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.