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 在列表中。
对于更灵活列表视图 Widget,使用 PySide.QtGui.QListView 类采用标准模型。
列表 Widget 的构造方式如同其它小部件:
listWidget = QListWidget(self)
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() 函数。
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 PySide.QtGui.QListWidget.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, 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. |
另请参阅
PySide.QtGui.QListWidgetItem PySide.QtGui.QListView PySide.QtGui.QTreeView 模型/视图编程 Config Dialog Example
| 参数: | parent – PySide.QtGui.QWidget |
|---|
构造空 PySide.QtGui.QListWidget 采用给定 parent .
| 参数: | label – unicode |
|---|
Inserts an item with the text label at the end of the list widget.
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
插入 item at the end of the list widget.
警告
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.
| 参数: | labels – list of strings |
|---|
Inserts items with the text labels at the end of the list widget.
移除视图中的所有项和选定。
警告
所有项会被永久删除。
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
Closes the persistent editor for the given item .
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the number of items in the list including any hidden items..
| 返回类型: | PySide.QtGui.QListWidgetItem |
|---|
返回当前项。
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the row of the current item..
Depending on the current selection mode, the row may also be selected.
| 参数: | currentRow – PySide.QtCore.int |
|---|
| 参数: | currentText – unicode |
|---|
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
开始编辑 item 若它可编辑。
| 参数: |
|
|---|---|
| 返回类型: |
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|---|
| 返回类型: | PySide.QtCore.QModelIndex |
返回 PySide.QtCore.QModelIndex assocated with the given item .
| 参数: |
|
|---|
Inserts an item with the text label in the list widget at the position given by row .
| 参数: |
|
|---|
插入 item at the position in the list given by row .
| 参数: |
|
|---|
Inserts items from the list of labels into the list, starting at the given row .
| 返回类型: | 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.
默认值为 false。
| 参数: | row – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtGui.QListWidgetItem |
返回项占据给定 row in the list if one has been set; otherwise returns 0.
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: |
|
|---|---|
| 返回类型: |
这是重载函数。
返回指针指向项在坐标 ( x , y ). The coordinates are relative to the list widget's PySide.QtGui.QAbstractScrollArea.viewport() .
| 参数: | p – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtGui.QListWidgetItem |
返回指针指向项在坐标 p . The coordinates are relative to the list widget's PySide.QtGui.QAbstractScrollArea.viewport() .
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: | index – PySide.QtCore.QModelIndex |
|---|---|
| 返回类型: | PySide.QtGui.QListWidgetItem |
返回指针指向 PySide.QtGui.QListWidgetItem assocated with the given index .
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|---|
| 返回类型: | PySide.QtGui.QWidget |
Returns the widget displayed in the given item .
| 参数: | data – PySide.QtCore.QMimeData |
|---|---|
| 返回类型: |
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.
| 参数: | items – |
|---|---|
| 返回类型: | PySide.QtCore.QMimeData |
| 返回类型: | 字符串列表 |
|---|
Returns a list of MIME types that can be used to describe a list of listwidget items.
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
Opens an editor for the given item . The editor remains open after editing.
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
Removes the widget set on the given item .
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the row containing the given item .
| 参数: |
|---|
| 返回类型: |
|---|
Returns a list of all selected items in the list widget.
| 参数: |
|
|---|
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|
Sets the current item to item .
除非选定模式为 NoSelection , the item is also be selected.
| 参数: | 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.
| 参数: |
|
|---|
| 参数: |
|
|---|
设置 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 和子类 PySide.QtGui.QItemDelegate 代替。
| 参数: | 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.
默认值为 false。
| 参数: | order – PySide.QtCore.Qt.SortOrder |
|---|
| 返回类型: | PySide.QtCore.Qt.SortOrder |
|---|
| 返回类型: | PySide.QtCore.Qt.DropActions |
|---|
返回由此视图所支持的掉落动作。
另请参阅
Qt.DropActions
| 参数: | row – PySide.QtCore.int |
|---|---|
| 返回类型: | 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.
| 参数: | item – PySide.QtGui.QListWidgetItem |
|---|---|
| 返回类型: | PySide.QtCore.QRect |
返回项所占据的视口矩形在 item .