Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QListWidget Class

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

 #include <QListWidget>

Inherits: QListView.

Public Types

enum DragDropMode { NoDragDrop, DragOnly, DropOnly, DragDrop, InternalMove }
enum EditTrigger { NoEditTriggers, CurrentChanged, DoubleClicked, SelectedClicked, ..., AllEditTriggers }
flags EditTriggers
enum PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, ..., PdmPhysicalDpiY }
enum ScrollHint { EnsureVisible, PositionAtTop, PositionAtBottom, PositionAtCenter }
enum ScrollMode { ScrollPerItem, ScrollPerPixel }
enum SelectionBehavior { SelectItems, SelectRows, SelectColumns }
enum SelectionMode { SingleSelection, ContiguousSelection, ExtendedSelection, MultiSelection, NoSelection }

Properties

Public Functions

QAbstractItemView(QWidget * parent = 0)
QListWidget(QWidget * parent = 0)
~QAbstractItemView()
~QListWidget()
virtual ~QPaintDevice()
void addItem(const QString & label)
void addItem(QListWidgetItem * item)
void addItems(const QStringList & labels)
bool alternatingRowColors() const
int autoScrollMargin() const
void closePersistentEditor(QListWidgetItem * item)
int colorCount() const
int count() const
QModelIndex currentIndex() const
QListWidgetItem * currentItem() const
int currentRow() const
Qt::DropAction defaultDropAction() const
int depth() const
DragDropMode dragDropMode() const
bool dragDropOverwriteMode() const
bool dragEnabled() const
void editItem(QListWidgetItem * item)
EditTriggers editTriggers() const
QList<QListWidgetItem *> findItems(const QString & text, Qt::MatchFlags flags) const
bool hasAutoScroll() const
int height() const
int heightMM() const
ScrollMode horizontalScrollMode() const
QSize iconSize() const
virtual QModelIndex indexAt(const QPoint & point) const = 0
QWidget * indexWidget(const QModelIndex & index) const
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
void insertItem(int row, QListWidgetItem * item)
void insertItem(int row, const QString & label)
void insertItems(int row, const QStringList & labels)
bool isSortingEnabled() const
QListWidgetItem * item(int row) const
QListWidgetItem * itemAt(const QPoint & p) const
QListWidgetItem * itemAt(int x, int y) const
QAbstractItemDelegate * itemDelegate() const
QAbstractItemDelegate * itemDelegate(const QModelIndex & index) const
QAbstractItemDelegate * itemDelegateForColumn(int column) const
QAbstractItemDelegate * itemDelegateForRow(int row) const
QWidget * itemWidget(QListWidgetItem * item) const
virtual void keyboardSearch(const QString & search)
int logicalDpiX() const
int logicalDpiY() const
QAbstractItemModel * model() const
void openPersistentEditor(QListWidgetItem * item)
virtual QPaintEngine * paintEngine() const = 0
bool paintingActive() const
int physicalDpiX() const
int physicalDpiY() const
void removeItemWidget(QListWidgetItem * item)
QModelIndex rootIndex() const
int row(const QListWidgetItem * item) const
virtual void scrollTo(const QModelIndex & index, ScrollHint hint = EnsureVisible) = 0
QList<QListWidgetItem *> selectedItems() const
QAbstractItemView::SelectionBehavior selectionBehavior() const
QAbstractItemView::SelectionMode selectionMode() const
QItemSelectionModel * selectionModel() const
void setAlternatingRowColors(bool enable)
void setAutoScroll(bool enable)
void setAutoScrollMargin(int margin)
void setCurrentItem(QListWidgetItem * item)
void setCurrentItem(QListWidgetItem * item, QItemSelectionModel::SelectionFlags command)
void setCurrentRow(int row)
void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
void setDefaultDropAction(Qt::DropAction dropAction)
void setDragDropMode(DragDropMode behavior)
void setDragDropOverwriteMode(bool overwrite)
void setDragEnabled(bool enable)
void setDropIndicatorShown(bool enable)
void setEditTriggers(EditTriggers triggers)
void setHorizontalScrollMode(ScrollMode mode)
void setIconSize(const QSize & size)
void setIndexWidget(const QModelIndex & index, QWidget * widget)
void setItemDelegate(QAbstractItemDelegate * delegate)
void setItemDelegateForColumn(int column, QAbstractItemDelegate * delegate)
void setItemDelegateForRow(int row, QAbstractItemDelegate * delegate)
void setItemWidget(QListWidgetItem * item, QWidget * widget)
virtual void setModel(QAbstractItemModel * model)
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
virtual void setSelectionModel(QItemSelectionModel * selectionModel)
void setSortingEnabled(bool enable)
void setTabKeyNavigation(bool enable)
void setTextElideMode(Qt::TextElideMode mode)
void setVerticalScrollMode(ScrollMode mode)
bool showDropIndicator() const
virtual int sizeHintForColumn(int column) const
QSize sizeHintForIndex(const QModelIndex & index) const
virtual int sizeHintForRow(int row) const
void sortItems(Qt::SortOrder order = Qt::AscendingOrder)
bool tabKeyNavigation() const
QListWidgetItem * takeItem(int row)
Qt::TextElideMode textElideMode() const
ScrollMode verticalScrollMode() const
QRect visualItemRect(const QListWidgetItem * item) const
virtual QRect visualRect(const QModelIndex & index) const = 0
int width() const
int widthMM() const

Reimplemented Public Functions

virtual void dropEvent(QDropEvent * event)

Public Slots

void clear()
void clearSelection()
void edit(const QModelIndex & index)
virtual void reset()
void scrollToBottom()
void scrollToItem(const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible)
void scrollToTop()
virtual void selectAll()
void setCurrentIndex(const QModelIndex & index)
virtual void setRootIndex(const QModelIndex & index)
void update(const QModelIndex & index)
  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

void activated(const QModelIndex & index)
void clicked(const QModelIndex & index)
void currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
void currentRowChanged(int currentRow)
void currentTextChanged(const QString & currentText)
void doubleClicked(const QModelIndex & index)
void entered(const QModelIndex & index)
void itemActivated(QListWidgetItem * item)
void itemChanged(QListWidgetItem * item)
void itemClicked(QListWidgetItem * item)
void itemDoubleClicked(QListWidgetItem * item)
void itemEntered(QListWidgetItem * item)
void itemPressed(QListWidgetItem * item)
void itemSelectionChanged()
void pressed(const QModelIndex & index)
void viewportEntered()

Protected Types

enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight, ..., MovePrevious }
enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport }
enum State { NoState, DraggingState, DragSelectingState, EditingState, ..., AnimatingState }

Protected Functions

QPaintDevice()
QPoint dirtyRegionOffset() const
virtual void dragEnterEvent(QDragEnterEvent * event)
virtual void dragLeaveEvent(QDragLeaveEvent * event)
virtual void dragMoveEvent(QDragMoveEvent * event)
virtual void dropEvent(QDropEvent * event)
DropIndicatorPosition dropIndicatorPosition() const
virtual bool dropMimeData(int index, const QMimeData * data, Qt::DropAction action)
virtual bool edit(const QModelIndex & index, EditTrigger trigger, QEvent * event)
virtual bool event(QEvent * event)
void executeDelayedItemsLayout()
virtual void focusInEvent(QFocusEvent * event)
virtual bool focusNextPrevChild(bool next)
virtual void focusOutEvent(QFocusEvent * event)
virtual int horizontalOffset() const = 0
QModelIndex indexFromItem(QListWidgetItem * item) const
virtual void init(QPainter * painter) const
virtual void inputMethodEvent(QInputMethodEvent * event)
virtual bool isIndexHidden(const QModelIndex & index) const = 0
QListWidgetItem * itemFromIndex(const QModelIndex & index) const
QList<QListWidgetItem *> items(const QMimeData * data) const
virtual void keyPressEvent(QKeyEvent * event)
virtual int metric(PaintDeviceMetric metric) const
virtual QMimeData * mimeData(const QList<QListWidgetItem *> items) const
virtual QStringList mimeTypes() const
virtual void mouseDoubleClickEvent(QMouseEvent * event)
virtual void mouseMoveEvent(QMouseEvent * event)
virtual void mousePressEvent(QMouseEvent * event)
virtual void mouseReleaseEvent(QMouseEvent * event)
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) = 0
virtual QPaintDevice * redirected(QPoint * offset) const
virtual void resizeEvent(QResizeEvent * event)
void scheduleDelayedItemsLayout()
void scrollDirtyRegion(int dx, int dy)
virtual QModelIndexList selectedIndexes() const
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex & index, const QEvent * event = 0) const
void setDirtyRegion(const QRegion & region)
virtual void setSelection(const QRect & rect, QItemSelectionModel::SelectionFlags flags) = 0
void setState(State state)
virtual QPainter * sharedPainter() const
virtual void startDrag(Qt::DropActions supportedActions)
State state() const
virtual Qt::DropActions supportedDropActions() const
virtual void timerEvent(QTimerEvent * event)
virtual int verticalOffset() const = 0
virtual QStyleOptionViewItem viewOptions() const
virtual bool viewportEvent(QEvent * event)
virtual QRegion visualRegionForSelection(const QItemSelection & selection) const = 0

Reimplemented Protected Functions

virtual bool event(QEvent * e)
  • 26 protected functions inherited from QListView
  • 18 protected functions inherited from QAbstractScrollArea
  • 3 protected functions inherited from QFrame
  • 37 protected functions inherited from QWidget
  • 9 protected functions inherited from QObject

Protected Slots

virtual void closeEditor(QWidget * editor, QAbstractItemDelegate::EndEditHint hint)
virtual void commitData(QWidget * editor)
virtual void currentChanged(const QModelIndex & current, const QModelIndex & previous)
virtual void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QSet<int> & roles = QSet<int> ())
virtual void editorDestroyed(QObject * editor)
virtual void rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end)
virtual void rowsInserted(const QModelIndex & parent, int start, int end)
virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
virtual void updateGeometries()
  • 1 protected slot inherited from QWidget

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 11 static public members inherited from QObject

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. QListWidget uses an internal model to manage each QListWidgetItem in the list.

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 = new QListWidget(this);

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, 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.

Screenshot of a Windows XP style list widgetScreenshot of a Macintosh style table widgetScreenshot of a Plastique style table widget
A Windows XP style list widget.A Macintosh style list widget.A Plastique style list widget.

See also QListWidgetItem, QListView, QTreeView, Model/View Programming, and Config Dialog Example.

Property Documentation

count : const int

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

Access functions:

int count() const

currentRow : int

This property holds the row of the current item.

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

Access functions:

int currentRow() const
void setCurrentRow(int row)
void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)

Notifier signal:

void currentRowChanged(int currentRow)

sortingEnabled : 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.

The default value is false.

This property was introduced in Qt 4.2.

Access functions:

bool isSortingEnabled() const
void setSortingEnabled(bool enable)

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::addItem(const QString & label)

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

void QListWidget::addItem(QListWidgetItem * item)

Inserts the item at the end of the list widget.

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

See also insertItem().

void QListWidget::addItems(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 and selections in the view.

Warning: All items will be permanently deleted.

void QListWidget::closePersistentEditor(QListWidgetItem * item)

Closes the persistent editor for the given item.

See also openPersistentEditor().

QListWidgetItem * QListWidget::currentItem() const

Returns the current item.

See also setCurrentItem().

void QListWidget::currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous) [signal]

This signal is emitted whenever the current item changes.

previous is the item that previously had the focus; current is the new current item.

void QListWidget::currentTextChanged(const QString & currentText) [signal]

This signal is emitted whenever the current item changes.

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

void QListWidget::dropEvent(QDropEvent * event) [virtual]

Reimplemented from QWidget::dropEvent().

bool QListWidget::dropMimeData(int index, const QMimeData * data, Qt::DropAction action) [virtual protected]

Handles data supplied by an external drag and drop operation that ended with the given action in the given index. Returns true if data and action can be handled by the model; otherwise returns false.

See also supportedDropActions().

void QListWidget::editItem(QListWidgetItem * item)

Starts editing the item if it is editable.

bool QListWidget::event(QEvent * e) [virtual protected]

Reimplemented from QObject::event().

QList<QListWidgetItem *> QListWidget::findItems(const QString & text, Qt::MatchFlags flags) const

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

QModelIndex QListWidget::indexFromItem(QListWidgetItem * item) const [protected]

Returns the QModelIndex assocated with the given item.

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

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

See also addItem().

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

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

See also addItem().

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

QListWidgetItem * QListWidget::item(int row) const

Returns the item that occupies the given row in the list if one has been set; otherwise returns 0.

See also row().

void QListWidget::itemActivated(QListWidgetItem * item) [signal]

This signal is emitted when the 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 is the Return key, on Mac OS X it is Ctrl+0).

QListWidgetItem * QListWidget::itemAt(const QPoint & p) const

Returns a pointer to the item at the coordinates p. The coordinates are relative to the list widget's viewport().

QListWidgetItem * QListWidget::itemAt(int x, int y) const

This is an overloaded function.

Returns a pointer to the item at the coordinates (x, y). The coordinates are relative to the list widget's viewport().

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

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

void QListWidget::itemClicked(QListWidgetItem * item) [signal]

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

See also itemPressed() and itemDoubleClicked().

void QListWidget::itemDoubleClicked(QListWidgetItem * item) [signal]

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

See also itemClicked() and itemPressed().

void QListWidget::itemEntered(QListWidgetItem * item) [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 item.

See also QWidget::setMouseTracking().

QListWidgetItem * QListWidget::itemFromIndex(const QModelIndex & index) const [protected]

Returns a pointer to the QListWidgetItem assocated with the given index.

void QListWidget::itemPressed(QListWidgetItem * item) [signal]

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

See also itemClicked() and itemDoubleClicked().

void QListWidget::itemSelectionChanged() [signal]

This signal is emitted whenever the selection changes.

See also selectedItems(), QListWidgetItem::isSelected(), and currentItemChanged().

QWidget * QListWidget::itemWidget(QListWidgetItem * item) const

Returns the widget displayed in the given item.

This function was introduced in Qt 4.1.

See also setItemWidget().

QList<QListWidgetItem *> QListWidget::items(const QMimeData * data) const [protected]

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.

QMimeData * QListWidget::mimeData(const QList<QListWidgetItem *> items) const [virtual protected]

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

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

QStringList QListWidget::mimeTypes() const [virtual protected]

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

See also mimeData().

void QListWidget::openPersistentEditor(QListWidgetItem * item)

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

See also closePersistentEditor().

void QListWidget::removeItemWidget(QListWidgetItem * item)

Removes the widget set on the given item.

This function was introduced in Qt 4.3.

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

Returns the row containing the given item.

See also item().

void QListWidget::scrollToItem(const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible) [slot]

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

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

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

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

void QListWidget::setCurrentItem(QListWidgetItem * item)

Sets the current item to item.

Unless the selection mode is NoSelection, the item is also be selected.

See also currentItem().

void QListWidget::setCurrentItem(QListWidgetItem * item, QItemSelectionModel::SelectionFlags command)

Set the current item to item, using the given command.

This function was introduced in Qt 4.4.

void QListWidget::setItemWidget(QListWidgetItem * item, QWidget * widget)

Sets the 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 and subclass QItemDelegate instead.

This function was introduced in Qt 4.1.

See also itemWidget() and Delegate Classes.

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

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

Qt::DropActions QListWidget::supportedDropActions() const [virtual protected]

Returns the drop actions supported by this view.

See also Qt::DropActions.

QListWidgetItem * QListWidget::takeItem(int row)

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.

See also insertItem() and addItem().

QRect QListWidget::visualItemRect(const QListWidgetItem * item) const

Returns the rectangle on the viewport occupied by the item at item.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web