Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QListWidget Class Reference

The QListWidget class provides an item-based list widget. More...

    #include <QListWidget>

Inherits QListView.

- List of all members, including inherited members

### Writable Properties

- 9 writable properties inherited from QListView
- 7 writable properties inherited from QAbstractItemView
- 2 writable properties inherited from QViewport
- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- 1 read-only property inherited from QViewport
- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QListWidget ( QWidget * parent = 0 )
- ~QListWidget ()
- void appendItem ( QListWidgetItem * item )
- void appendItem ( const QString & label )
- void appendItems ( const QStringList & labels )
- void closePersistentEditor ( QListWidgetItem * item )
- int count () const
- QListWidgetItem * currentItem () const
- QList<QListWidgetItem *> findItems ( const QString & text, QAbstractItemModel::MatchFlags flags = QAbstractItemModel::MatchDefault ) const
- void insertItem ( int row, QListWidgetItem * item )
- void insertItem ( int row, const QString & label )
- void insertItems ( int row, const QStringList & labels )
- bool isItemHidden ( const QListWidgetItem * item ) const
- bool isItemVisible ( const QListWidgetItem * item ) const
- bool isSelected ( const QListWidgetItem * item ) const
- QListWidgetItem * item ( int row ) const
- void openPersistentEditor ( QListWidgetItem * item )
- int row ( const QListWidgetItem * item ) const
- QList<QListWidgetItem *> selectedItems () const
- void setCurrentItem ( QListWidgetItem * item )
- void setItemHidden ( const QListWidgetItem * item, bool hide )
- void setSelected ( const QListWidgetItem * item, bool select )
- void sortItems ( Qt::SortOrder order = Qt::AscendingOrder )
- QListWidgetItem * takeItem ( int row )

- 3 public functions inherited from QListView
- 22 public functions inherited from QAbstractItemView
- 4 public functions inherited from QViewport
- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void clear ()
- void ensureItemVisible ( const QListWidgetItem * item )

- 6 public slots inherited from QAbstractItemView
- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void aboutToShowContextMenu ( QMenu * menu, QListWidgetItem * item )
- void clicked ( QListWidgetItem * item, Qt::ButtonState button )
- void currentChanged ( QListWidgetItem * current, QListWidgetItem * previous )
- void doubleClicked ( QListWidgetItem * item, Qt::ButtonState button )
- void itemChanged ( QListWidgetItem * item )
- void itemEntered ( QListWidgetItem * item, Qt::ButtonState state )
- void keyPressed ( QListWidgetItem * item, Qt::Key key, Qt::ButtonState state )
- void pressed ( QListWidgetItem * item, Qt::ButtonState button )
- void returnPressed ( QListWidgetItem * item )
- void selectionChanged ()

- 9 signals inherited from QAbstractItemView
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- 1 protected function inherited from QListView
- 33 protected functions inherited from QAbstractItemView
- 17 protected functions inherited from QViewport
- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

### Protected Slots

- 8 protected slots inherited from QAbstractItemView

## Detailed Description

The QListWidget class provides an item-based list 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 from the list. QListWidget uses an internal model to manage the items.

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:

            QListWidget *listWidget;

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 the setSelectionMode() 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:

            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, it is more convenient to construct the item without a parent widget and use the insertItem() function to place it within the list:

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

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 currentChanged() signal is emitted with the new current item and the item that was previously current.

See also QListWidgetItem and Model/View Programming.

## Member Function Documentation

### QListWidget::QListWidget ( QWidget * parent = 0 )

Constructs an empty QListWidget with the given parent.

### QListWidget::~QListWidget ()

Destroys the list widget and all its items.

### void QListWidget::aboutToShowContextMenu ( QMenu * menu, QListWidgetItem * item ) `[signal]`

This signal is emitted when the widget is about to show a context menu. The menu is the menu about to be shown, and the item is the clicked item the context menu was called for.

See also QMenu::addAction().

### void QListWidget::appendItem ( QListWidgetItem * item )

Inserts the item at the the end of the list widget.

See also insertItem().

### void QListWidget::appendItem ( const QString & label )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

### void QListWidget::appendItems ( const QStringList & labels )

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

See also insertItems().

### void QListWidget::clear () `[slot]`

Removes all items in the view.

### void QListWidget::clicked ( QListWidgetItem * item, Qt::ButtonState button ) `[signal]`

This signal is emitted when a mouse button is clicked. The item may be 0 if the mouse was not clicked on an item. The button clicked is specified by button (see Qt::ButtonState).

### void QListWidget::closePersistentEditor ( QListWidgetItem * item )

Closes the persistent editor for the given item.

See also openPersistentEditor().

### int QListWidget::count () const

Returns the number of items in the list.

### void QListWidget::currentChanged ( QListWidgetItem * current, QListWidgetItem * previous ) `[signal]`

This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.

### QListWidgetItem * QListWidget::currentItem () const

Returns the current item.

### void QListWidget::doubleClicked ( QListWidgetItem * item, Qt::ButtonState button ) `[signal]`

This signal is emitted when a mouse button is double clicked. The item may be 0 if the mouse was not clicked on an item. The button clicked is specified by button (see Qt::ButtonState).

### void QListWidget::ensureItemVisible ( const QListWidgetItem * item ) `[slot]`

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

### QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, QAbstractItemModel::MatchFlags flags = QAbstractItemModel::MatchDefault ) const

Finds items that matches the text, using the criteria given in the flags (see QAbstractItemModel::MatchFlags).

### void QListWidget::insertItem ( int row, QListWidgetItem * item )

Inserts the item at the position in the list given by row.

See also appendItem().

### void QListWidget::insertItem ( int row, const QString & label )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

See also appendItem().

### void QListWidget::insertItems ( int row, const QStringList & labels )

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

See also insertItem() and appendItem().

### bool QListWidget::isItemHidden ( const QListWidgetItem * item ) const

Returns true if the item is explicitly hidden; otherwise returns false.

### bool QListWidget::isItemVisible ( const QListWidgetItem * item ) const

Returns true if the item is in the viewport; otherwise returns false.

### bool QListWidget::isSelected ( const QListWidgetItem * item ) const

Returns true if item is selected; otherwise returns false.

### QListWidgetItem * QListWidget::item ( int row ) const

Returns the item that occupies the given row in the list.

See also row().

### void QListWidget::itemChanged ( QListWidgetItem * item ) `[signal]`

This signal is emitted whenever the data of item has changed.

### void QListWidget::itemEntered ( QListWidgetItem * item, Qt::ButtonState state ) `[signal]`

This signal is emitted when the mouse cursor enters an item. The item is the item entered and state specifies the mouse button and any modifiers pressed as the item was entered (see Qt::ButtonState). This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.

### void QListWidget::keyPressed ( QListWidgetItem * item, Qt::Key key, Qt::ButtonState state ) `[signal]`

This signal is emitted if keyTracking is turned on an a key was pressed. The item is the current item when the key was pressed, the key tells which key was pressed and state which modifier keys (see Qt::ButtonState).

### void QListWidget::openPersistentEditor ( QListWidgetItem * item )

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

See also closePersistentEditor().

### void QListWidget::pressed ( QListWidgetItem * item, Qt::ButtonState button ) `[signal]`

This signal is emitted when a item has been pressed (mouse click and release). The item may be 0 if the mouse was not pressed on an item. The button clicked is specified by button (see Qt::ButtonState).

### void QListWidget::returnPressed ( QListWidgetItem * item ) `[signal]`

This signal is emitted when return has been pressed on an item.

### int QListWidget::row ( const QListWidgetItem * item ) const

Returns the row containing the given item.

See also item().

### QList<QListWidgetItem *> QListWidget::selectedItems () const

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

### void QListWidget::selectionChanged () `[signal]`

This signal is emitted whenever the selection changes.

See also selectedItems() and isSelected().

### void QListWidget::setCurrentItem ( QListWidgetItem * item )

Sets the current item to item.

### void QListWidget::setItemHidden ( const QListWidgetItem * item, bool hide )

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

### void QListWidget::setSelected ( const QListWidgetItem * item, bool select )

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

### void QListWidget::sortItems ( Qt::SortOrder order = Qt::AscendingOrder )

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

### QListWidgetItem * QListWidget::takeItem ( int row )

Removes and returns the item from the given row in the list widget, otherwise return 0;

See also insertItem() and appendItem().