QListWidget Class Reference

[ QtGui module]

QListWidget 类提供基于项的列表 Widget。 更多...

继承 QListView .

方法

Special Methods

Qt Signals


详细描述

QListWidget 类提供基于项的列表 Widget。

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 类采用标准模型。

List widgets are constructed in the same way as other widgets:

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

Screenshot of a Windows XP style list widget Screenshot of a Macintosh style table widget Screenshot of a Plastique style table widget
A Windows XP style list 小部件。 A Macintosh style list 小部件。 A Plastique style list 小部件。

方法文档编制

QListWidget.__init__ ( self , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造空 QListWidget with the given parent .

QListWidget.addItem ( self , QListWidgetItem   aitem )

aitem argument has it's ownership transferred to Qt.

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

QListWidget.addItem ( self , QString  label )

插入 item at the end of the list widget.

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

另请参阅 insertItem ().

QListWidget.addItems ( self , QStringList  labels )

Inserts items with the text labels at the end of the list 小部件。

另请参阅 insertItems ().

QListWidget.clear ( self )

This method is also a Qt slot with the C++ signature void clear() .

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

警告: 所有项会被永久删除。

QListWidget.closePersistentEditor ( self , QListWidgetItem   item )

Closes the persistent editor for the given item .

另请参阅 openPersistentEditor ().

int QListWidget.count ( self )

QListWidgetItem QListWidget.currentItem ( self )

返回当前项。

另请参阅 setCurrentItem ().

int QListWidget.currentRow ( self )

QListWidget.dropEvent ( self , QDropEvent   event )

重实现自 QWidget.dropEvent ().

bool QListWidget.dropMimeData ( self , int  index , QMimeData   data , Qt.DropAction   action )

Handles data supplied by an external drag and drop operation that ended with the given action 以给定 index . Returns true if data and action 可以是 handled by the model; otherwise returns false.

另请参阅 supportedDropActions ().

QListWidget.editItem ( self , QListWidgetItem   item )

开始编辑 item 若它可编辑。

bool QListWidget.event ( self , QEvent   e )

重实现自 QObject.event ().

list-of-QListWidgetItem QListWidget.findItems ( self , QString  text , Qt.MatchFlags   flags )

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

QModelIndex QListWidget.indexFromItem ( self , QListWidgetItem   item )

返回 QModelIndex assocated with the given item .

QListWidget.insertItem ( self , int  row , QListWidgetItem   item )

item argument has it's ownership transferred to Qt.

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

另请参阅 addItem ().

QListWidget.insertItem ( self , int  row , QString  label )

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

另请参阅 addItem ().

QListWidget.insertItems ( self , int  row , QStringList  labels )

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

另请参阅 insertItem () 和 addItem ().

bool QListWidget.isItemHidden ( self , QListWidgetItem   item )

bool QListWidget.isItemSelected ( self , QListWidgetItem   item )

bool QListWidget.isSortingEnabled ( self )

QListWidgetItem QListWidget.item ( self , int  row )

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

另请参阅 row ().

QListWidgetItem QListWidget.itemAt ( self , QPoint   p )

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

QListWidgetItem QListWidget.itemAt ( self , int  ax , int  ay )

这是重载函数。

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

QListWidgetItem QListWidget.itemFromIndex ( self , QModelIndex   index )

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

list-of-QListWidgetItem QListWidget.items ( self , QMimeData   data )

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.

QWidget QListWidget.itemWidget ( self , QListWidgetItem   item )

Returns the widget displayed in the given item .

该函数在 Qt 4.1 引入。

另请参阅 setItemWidget ().

QMimeData QListWidget.mimeData ( self , list-of-QListWidgetItem  items )

QMimeData result

Returns an object that contains a serialized description of the specified items . The format used to describe the items is obtained from the mimeTypes () 函数。

If the list of items is empty, 0 is returned instead of a serialized empty list.

QStringList QListWidget.mimeTypes ( self )

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

另请参阅 mimeData ().

QListWidget.openPersistentEditor ( self , QListWidgetItem   item )

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

另请参阅 closePersistentEditor ().

QListWidget.removeItemWidget ( self , QListWidgetItem   aItem )

Removes the widget set on the given item .

该函数在 Qt 4.3 引入。

int QListWidget.row ( self , QListWidgetItem   item )

Returns the row containing the given item .

另请参阅 item ().

QListWidget.scrollToItem ( self , QListWidgetItem   item , QAbstractItemView.ScrollHint   hint  = QAbstractItemView.EnsureVisible)

This method is also a Qt slot with the C++ signature void scrollToItem(const QListWidgetItem*,QAbstractItemView::ScrollHint = QAbstractItemView.EnsureVisible) .

Scrolls the view if necessary to ensure that the item is visible.

hint specifies where the item should be located after the operation.

list-of-QListWidgetItem QListWidget.selectedItems ( self )

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

QListWidget.setCurrentItem ( self , QListWidgetItem   item )

Sets the current item to item .

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

另请参阅 currentItem ().

QListWidget.setCurrentItem ( self , QListWidgetItem   item , QItemSelectionModel.SelectionFlags   command )

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

该函数在 Qt 4.4 引入。

QListWidget.setCurrentRow ( self , int  row )

QListWidget.setCurrentRow ( self , int  row , QItemSelectionModel.SelectionFlags   command )

QListWidget.setItemHidden ( self , QListWidgetItem   item , bool  hide )

QListWidget.setItemSelected ( self , QListWidgetItem   item , bool  select )

QListWidget.setItemWidget ( self , QListWidgetItem   item , QWidget   widget )

widget argument has it's ownership transferred to Qt.

设置 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 QListView 和子类 QItemDelegate 代替。

该函数在 Qt 4.1 引入。

另请参阅 itemWidget () 和 Delegate 类 .

QListWidget.setSortingEnabled ( self , bool  enable )

QListWidget.sortItems ( self , Qt.SortOrder   order  = Qt.AscendingOrder)

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

Qt.DropActions QListWidget.supportedDropActions ( self )

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

另请参阅 Qt.DropActions .

QListWidgetItem QListWidget.takeItem ( self , int  row )

QListWidgetItem result

Removes and returns the item from the given row 在 list widget; otherwise returns 0.

Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

另请参阅 insertItem () 和 addItem ().

QRect QListWidget.visualItemRect ( self , QListWidgetItem   item )

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

QListWidget.__len__ ( self )


Qt Signal Documentation

void currentItemChanged (QListWidgetItem*,QListWidgetItem*)

This is the default overload of this signal.

此信号被发射每当当前项改变时。

上一 是先前有聚焦的项; current 是新的当前项。

void currentRowChanged (int)

This is the default overload of this signal.

此信号被发射每当当前项改变时。

currentRow is the row of the current item. If there is no current item, the currentRow is -1.

void currentTextChanged (const QString&)

This is the default overload of this signal.

此信号被发射每当当前项改变时。

currentText is the text data in the current item. If there is no current item, the currentText is invalid.

void itemActivated (QListWidgetItem*)

This is the default overload of this signal.

此信号被发射当 item is activated. The item is activated when the user clicks or double clicks on it, depending on the system configuration. It is also activated when the user presses the activation key (on Windows and X11 this 是 返回 key, on Mac OS X it is Ctrl+0 ).

void itemChanged (QListWidgetItem*)

This is the default overload of this signal.

This signal is emitted whenever the data of item has 改变。

void itemClicked (QListWidgetItem*)

This is the default overload of this signal.

This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.

另请参阅 itemPressed () 和 itemDoubleClicked ().

void itemDoubleClicked (QListWidgetItem*)

This is the default overload of this signal.

This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.

另请参阅 itemClicked () 和 itemPressed ().

void itemEntered (QListWidgetItem*)

This is the default overload of this signal.

This signal is emitted when the mouse cursor enters an item. The item is the item entered. This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an 项。

另请参阅 QWidget.setMouseTracking ().

void itemPressed (QListWidgetItem*)

This is the default overload of this signal.

This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.

另请参阅 itemClicked () 和 itemDoubleClicked ().

void itemSelectionChanged ()

This is the default overload of this signal.

此信号被发射每当选定改变。

另请参阅 selectedItems (), QListWidgetItem.isSelected (), and currentItemChanged ().