• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QUndoView

    下一话题

    QToolBar

    QListWidget

    概要

    函数

    虚函数

    信号

    详细描述

    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.

    ../../_images/windowsxp-listview.png ../../_images/macintosh-listview.png ../../_images/plastique-listview.png
    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

    class PySide.QtGui. QListWidget ( [ parent=None ] )
    参数: parent PySide.QtGui.QWidget

    构造空 PySide.QtGui.QListWidget 采用给定 parent .

    PySide.QtGui.QListWidget. addItem ( label )
    参数: label – unicode

    Inserts an item with the text label at the end of the list widget.

    PySide.QtGui.QListWidget. addItem ( item )
    参数: 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.

    PySide.QtGui.QListWidget. addItems ( labels )
    参数: labels – list of strings

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

    PySide.QtGui.QListWidget. clear ( )

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

    警告

    所有项会被永久删除。

    PySide.QtGui.QListWidget. closePersistentEditor ( item )
    参数: item PySide.QtGui.QListWidgetItem

    Closes the persistent editor for the given item .

    PySide.QtGui.QListWidget. count ( )
    返回类型: PySide.QtCore.int

    This property holds the number of items in the list including any hidden items..

    PySide.QtGui.QListWidget. currentItem ( )
    返回类型: PySide.QtGui.QListWidgetItem

    返回当前项。

    PySide.QtGui.QListWidget. currentItemChanged ( current , 上一 )
    参数:
    PySide.QtGui.QListWidget. currentRow ( )
    返回类型: PySide.QtCore.int

    This property holds the row of the current item..

    Depending on the current selection mode, the row may also be selected.

    PySide.QtGui.QListWidget. currentRowChanged ( currentRow )
    参数: currentRow PySide.QtCore.int
    PySide.QtGui.QListWidget. currentTextChanged ( currentText )
    参数: currentText – unicode
    PySide.QtGui.QListWidget. dropMimeData ( index , data , action )
    参数:
    返回类型:

    PySide.QtCore.bool

    PySide.QtGui.QListWidget. editItem ( item )
    参数: item PySide.QtGui.QListWidgetItem

    开始编辑 item 若它可编辑。

    PySide.QtGui.QListWidget. findItems ( text , flags )
    参数:
    • text – unicode
    • flags PySide.QtCore.Qt.MatchFlags
    返回类型:

    PySide.QtGui.QListWidget. indexFromItem ( item )
    参数: item PySide.QtGui.QListWidgetItem
    返回类型: PySide.QtCore.QModelIndex

    返回 PySide.QtCore.QModelIndex assocated with the given item .

    PySide.QtGui.QListWidget. insertItem ( row , label )
    参数:
    • row PySide.QtCore.int
    • label – unicode

    Inserts an item with the text label in the list widget at the position given by row .

    PySide.QtGui.QListWidget. insertItem ( row , item )
    参数:

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

    PySide.QtGui.QListWidget. insertItems ( row , labels )
    参数:
    • row PySide.QtCore.int
    • labels – list of strings

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

    PySide.QtGui.QListWidget. isSortingEnabled ( )
    返回类型: 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。

    PySide.QtGui.QListWidget. item ( row )
    参数: row PySide.QtCore.int
    返回类型: PySide.QtGui.QListWidgetItem

    返回项占据给定 row in the list if one has been set; otherwise returns 0.

    PySide.QtGui.QListWidget. itemActivated ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemAt ( x , y )
    参数:
    • x PySide.QtCore.int
    • y PySide.QtCore.int
    返回类型:

    PySide.QtGui.QListWidgetItem

    这是重载函数。

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

    PySide.QtGui.QListWidget. itemAt ( p )
    参数: p PySide.QtCore.QPoint
    返回类型: PySide.QtGui.QListWidgetItem

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

    PySide.QtGui.QListWidget. itemChanged ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemClicked ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemDoubleClicked ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemEntered ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemFromIndex ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtGui.QListWidgetItem

    返回指针指向 PySide.QtGui.QListWidgetItem assocated with the given index .

    PySide.QtGui.QListWidget. itemPressed ( item )
    参数: item PySide.QtGui.QListWidgetItem
    PySide.QtGui.QListWidget. itemSelectionChanged ( )
    PySide.QtGui.QListWidget. itemWidget ( item )
    参数: item PySide.QtGui.QListWidgetItem
    返回类型: PySide.QtGui.QWidget

    Returns the widget displayed in the given item .

    PySide.QtGui.QListWidget. items ( data )
    参数: 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.

    PySide.QtGui.QListWidget. mimeData ( items )
    参数: items
    返回类型: PySide.QtCore.QMimeData
    PySide.QtGui.QListWidget. mimeTypes ( )
    返回类型: 字符串列表

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

    PySide.QtGui.QListWidget. openPersistentEditor ( item )
    参数: item PySide.QtGui.QListWidgetItem

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

    PySide.QtGui.QListWidget. removeItemWidget ( item )
    参数: item PySide.QtGui.QListWidgetItem

    Removes the widget set on the given item .

    PySide.QtGui.QListWidget. row ( item )
    参数: item PySide.QtGui.QListWidgetItem
    返回类型: PySide.QtCore.int

    Returns the row containing the given item .

    PySide.QtGui.QListWidget. scrollToItem ( item [ , hint=EnsureVisible ] )
    参数:
    PySide.QtGui.QListWidget. selectedItems ( )
    返回类型:

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

    PySide.QtGui.QListWidget. setCurrentItem ( item , command )
    参数:
    PySide.QtGui.QListWidget. setCurrentItem ( item )
    参数: item PySide.QtGui.QListWidgetItem

    Sets the current item to item .

    除非选定模式为 NoSelection , the item is also be selected.

    PySide.QtGui.QListWidget. setCurrentRow ( row )
    参数: 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.

    PySide.QtGui.QListWidget. setCurrentRow ( row , command )
    参数:
    • row PySide.QtCore.int
    • command PySide.QtGui.QItemSelectionModel.SelectionFlags
    PySide.QtGui.QListWidget. setItemWidget ( item , widget )
    参数:

    设置 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 代替。

    PySide.QtGui.QListWidget. setSortingEnabled ( enable )
    参数: 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。

    PySide.QtGui.QListWidget. sortItems ( [ order=Qt.AscendingOrder ] )
    参数: order PySide.QtCore.Qt.SortOrder
    PySide.QtGui.QListWidget. sortOrder ( )
    返回类型: PySide.QtCore.Qt.SortOrder
    PySide.QtGui.QListWidget. supportedDropActions ( )
    返回类型: PySide.QtCore.Qt.DropActions

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

    另请参阅

    Qt.DropActions

    PySide.QtGui.QListWidget. takeItem ( row )
    参数: 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.

    PySide.QtGui.QListWidget. visualItemRect ( item )
    参数: item PySide.QtGui.QListWidgetItem
    返回类型: PySide.QtCore.QRect

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