内容表

上一话题

QListView

下一话题

QListWidgetItem

QListWidget

QListWidget class provides an item-based list widget. 更多

Inheritance diagram of PySide2.QtWidgets.QListWidget

概要

函数

虚函数

信号

详细描述

../../_images/windows-listview.png

QListWidget is 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. QListWidget uses an internal model to manage each QListWidgetItem 在列表中。

对于更灵活列表视图 Widget,使用 QListView 类采用标准模型。

列表 Widget 的构造方式如同其它小部件:

QListWidget *listWidget = new QListWidget(this);
											

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() 函数。

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:

new QListWidgetItem(tr("Oak"), listWidget);
new QListWidgetItem(tr("Fir"), listWidget);
new 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.

QListWidgetItem *newItem = new 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.

class QListWidget ( [ parent=None ] )
param parent

QWidget

构造空 QListWidget 采用给定 parent .

PySide2.QtWidgets.QListWidget. addItem ( label )
参数

label – unicode

PySide2.QtWidgets.QListWidget. addItem ( item )
参数

item QListWidgetItem

插入 item at the end of the list widget.

警告

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

另请参阅

insertItem()

PySide2.QtWidgets.QListWidget. addItems ( labels )
参数

labels – 字符串列表

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

另请参阅

insertItems()

PySide2.QtWidgets.QListWidget. clear ( )

移除视图中的所有项和选定。

警告

所有项会被永久删除。

PySide2.QtWidgets.QListWidget. closePersistentEditor ( item )
参数

item QListWidgetItem

Closes the persistent editor for the given item .

PySide2.QtWidgets.QListWidget. count ( )
返回类型

int

PySide2.QtWidgets.QListWidget. currentItem ( )
返回类型

QListWidgetItem

返回当前项。

另请参阅

setCurrentItem()

PySide2.QtWidgets.QListWidget. currentItemChanged ( current , 上一 )
参数
PySide2.QtWidgets.QListWidget. currentRow ( )
返回类型

int

另请参阅

setCurrentRow()

PySide2.QtWidgets.QListWidget. currentRowChanged ( currentRow )
参数

currentRow int

PySide2.QtWidgets.QListWidget. currentTextChanged ( currentText )
参数

currentText – unicode

PySide2.QtWidgets.QListWidget. dropMimeData ( index , data , action )
参数
  • index int

  • data QMimeData

  • action DropAction

返回类型

bool

Handles data supplied by an external drag and drop operation that ended with the given action 以给定 index 。返回 true if data and action can be handled by the model; otherwise returns false .

PySide2.QtWidgets.QListWidget. editItem ( item )
参数

item QListWidgetItem

开始编辑 item 若它可编辑。

PySide2.QtWidgets.QListWidget. findItems ( text , flags )
参数
  • text – unicode

  • flags MatchFlags

返回类型

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

PySide2.QtWidgets.QListWidget. indexFromItem ( item )
参数

item QListWidgetItem

返回类型

QModelIndex

返回 QModelIndex 关联给定 item .

注意

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

PySide2.QtWidgets.QListWidget. indexFromItem ( item )
参数

item QListWidgetItem

返回类型

QModelIndex

返回 QModelIndex 关联给定 item .

注意

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

PySide2.QtWidgets.QListWidget. insertItem ( row , label )
参数
  • row int

  • label – unicode

PySide2.QtWidgets.QListWidget. insertItem ( row , item )
参数

插入 item at the position in the list given by row .

另请参阅

addItem()

PySide2.QtWidgets.QListWidget. insertItems ( row , labels )
参数
  • row int

  • labels – 字符串列表

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

PySide2.QtWidgets.QListWidget. isItemHidden ( item )
参数

item QListWidgetItem

返回类型

bool

注意

此函数被弃用。

返回 true item is explicitly hidden; otherwise returns false .

This function is deprecated. Use isHidden() 代替。

PySide2.QtWidgets.QListWidget. isItemSelected ( item )
参数

item QListWidgetItem

返回类型

bool

注意

此函数被弃用。

返回 true if item is selected; otherwise returns false .

This function is deprecated. Use isSelected() 代替。

PySide2.QtWidgets.QListWidget. isPersistentEditorOpen ( item )
参数

item QListWidgetItem

返回类型

bool

返回是否打开持久编辑器为项 item .

PySide2.QtWidgets.QListWidget. isSortingEnabled ( )
返回类型

bool

PySide2.QtWidgets.QListWidget. item ( row )
参数

row int

返回类型

QListWidgetItem

返回项占据给定 row 在列表中,若有设置;否则返回 None .

另请参阅

row()

PySide2.QtWidgets.QListWidget. itemActivated ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemAt ( p )
参数

p QPoint

返回类型

QListWidgetItem

返回指针指向项在坐标 p . The coordinates are relative to the list widget’s viewport() .

PySide2.QtWidgets.QListWidget. itemAt ( x , y )
参数
  • x int

  • y int

返回类型

QListWidgetItem

这是重载函数。

返回指针指向项在坐标 ( x , y ). The coordinates are relative to the list widget’s viewport() .

PySide2.QtWidgets.QListWidget. itemChanged ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemClicked ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemDoubleClicked ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemEntered ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemFromIndex ( index )
参数

index QModelIndex

返回类型

QListWidgetItem

返回指针指向 QListWidgetItem 关联给定 index .

PySide2.QtWidgets.QListWidget. itemPressed ( item )
参数

item QListWidgetItem

PySide2.QtWidgets.QListWidget. itemSelectionChanged ( )
PySide2.QtWidgets.QListWidget. itemWidget ( item )
参数

item QListWidgetItem

返回类型

QWidget

Returns the widget displayed in the given item .

PySide2.QtWidgets.QListWidget. items ( data )
参数

data QMimeData

返回类型

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.

PySide2.QtWidgets.QListWidget. mimeData ( items )
参数

items

返回类型

QMimeData

返回对象包含序列化描述指定通过 items 。用于描述项的格式获取自 mimeTypes() 函数。

若项列表为空, None is returned instead of a serialized empty list.

PySide2.QtWidgets.QListWidget. mimeTypes ( )
返回类型

字符串列表

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

另请参阅

mimeData()

PySide2.QtWidgets.QListWidget. openPersistentEditor ( item )
参数

item QListWidgetItem

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

PySide2.QtWidgets.QListWidget. removeItemWidget ( item )
参数

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() .

PySide2.QtWidgets.QListWidget. row ( item )
参数

item QListWidgetItem

返回类型

int

Returns the row containing the given item .

另请参阅

item()

PySide2.QtWidgets.QListWidget. scrollToItem ( item [ , 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.

PySide2.QtWidgets.QListWidget. selectedItems ( )
返回类型

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

PySide2.QtWidgets.QListWidget. setCurrentItem ( item )
参数

item QListWidgetItem

Sets the current item to item .

除非选定模式为 NoSelection ,项还被选中。

另请参阅

currentItem()

PySide2.QtWidgets.QListWidget. setCurrentItem ( item , command )
参数

Set the current item to item ,使用给定 command .

PySide2.QtWidgets.QListWidget. setCurrentRow ( row , command )
参数
  • row int

  • command SelectionFlags

把当前行设为给定 row ,使用给定 command ,

PySide2.QtWidgets.QListWidget. setCurrentRow ( row )
参数

row int

另请参阅

currentRow()

PySide2.QtWidgets.QListWidget. setItemHidden ( item , hide )
参数

注意

此函数被弃用。

hide is true, the item will be hidden; otherwise it will be shown.

This function is deprecated. Use setHidden() 代替。

另请参阅

isItemHidden()

PySide2.QtWidgets.QListWidget. setItemSelected ( item , select )
参数

注意

此函数被弃用。

Selects or deselects the given item depending on whether select is true of false.

This function is deprecated. Use setSelected() 代替。

另请参阅

isItemSelected()

PySide2.QtWidgets.QListWidget. setItemWidget ( item , widget )
参数

设置 widget 以显示在给定 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 和子类 QStyledItemDelegate 代替。

PySide2.QtWidgets.QListWidget. setSortingEnabled ( enable )
参数

enable bool

PySide2.QtWidgets.QListWidget. sortItems ( [ order=Qt.AscendingOrder ] )
参数

order SortOrder

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

PySide2.QtWidgets.QListWidget. supportedDropActions ( )
返回类型

DropActions

返回由此视图所支持的掉落动作。

另请参阅

DropActions

PySide2.QtWidgets.QListWidget. takeItem ( row )
参数

row int

返回类型

QListWidgetItem

Removes and returns the item from the given row in 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.

PySide2.QtWidgets.QListWidget. visualItemRect ( item )
参数

item QListWidgetItem

返回类型

QRect

返回项所占据的视口矩形在 item .