1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qlistwidget.h"
44 #ifndef QT_NO_LISTWIDGET
45 #include <qitemdelegate.h>
46 #include <private/qlistview_p.h>
47 #include <private/qwidgetitemdata_p.h>
48 #include <private/qlistwidget_p.h>
52 // workaround for VC++ 6.0 linker bug (?)
53 typedef bool(*LessThan)(const QPair<QListWidgetItem*,int>&,const QPair<QListWidgetItem*,int>&);
55 class QListWidgetMimeData : public QMimeData
59 QList<QListWidgetItem*> items;
62 QT_BEGIN_INCLUDE_NAMESPACE
63 #include "qlistwidget.moc"
64 QT_END_INCLUDE_NAMESPACE
66 QListModel::QListModel(QListWidget *parent)
67 : QAbstractListModel(parent)
71 QListModel::~QListModel()
76 void QListModel::clear()
78 for (int i = 0; i < items.count(); ++i) {
80 items.at(i)->d->theid = -1;
81 items.at(i)->view = 0;
89 QListWidgetItem *QListModel::at(int row) const
91 return items.value(row);
94 void QListModel::remove(QListWidgetItem *item)
98 int row = items.indexOf(item); // ### use index(item) - it's faster
100 beginRemoveRows(QModelIndex(), row, row);
101 items.at(row)->d->theid = -1;
102 items.at(row)->view = 0;
107 void QListModel::insert(int row, QListWidgetItem *item)
112 item->view = qobject_cast<QListWidget*>(QObject::parent());
113 if (item->view && item->view->isSortingEnabled()) {
115 QList<QListWidgetItem*>::iterator it;
116 it = sortedInsertionIterator(items.begin(), items.end(),
117 item->view->sortOrder(), item);
118 row = qMax(it - items.begin(), 0);
122 else if (row > items.count())
125 beginInsertRows(QModelIndex(), row, row);
126 items.insert(row, item);
127 item->d->theid = row;
131 void QListModel::insert(int row, const QStringList &labels)
133 const int count = labels.count();
136 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
137 if (view && view->isSortingEnabled()) {
139 for (int i = 0; i < count; ++i) {
140 QListWidgetItem *item = new QListWidgetItem(labels.at(i));
146 else if (row > items.count())
148 beginInsertRows(QModelIndex(), row, row + count - 1);
149 for (int i = 0; i < count; ++i) {
150 QListWidgetItem *item = new QListWidgetItem(labels.at(i));
151 item->d->theid = row;
152 item->view = qobject_cast<QListWidget*>(QObject::parent());
153 items.insert(row++, item);
159 QListWidgetItem *QListModel::take(int row)
161 if (row < 0 || row >= items.count())
164 beginRemoveRows(QModelIndex(), row, row);
165 items.at(row)->d->theid = -1;
166 items.at(row)->view = 0;
167 QListWidgetItem *item = items.takeAt(row);
172 void QListModel::move(int srcRow, int dstRow)
175 || srcRow < 0 || srcRow >= items.count()
176 || dstRow < 0 || dstRow > items.count())
179 if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow))
183 items.move(srcRow, dstRow);
187 int QListModel::rowCount(const QModelIndex &parent) const
189 return parent.isValid() ? 0 : items.count();
192 QModelIndex QListModel::index(QListWidgetItem *item) const
194 if (!item || !item->view || static_cast<const QListModel *>(item->view->model()) != this
196 return QModelIndex();
198 const int theid = item->d->theid;
199 if (theid >= 0 && theid < items.count() && items.at(theid) == item) {
201 } else { // we need to search for the item
202 row = items.lastIndexOf(item); // lastIndexOf is an optimization in favor of indexOf
203 if (row == -1) // not found
204 return QModelIndex();
205 item->d->theid = row;
207 return createIndex(row, 0, item);
210 QModelIndex QListModel::index(int row, int column, const QModelIndex &parent) const
212 if (hasIndex(row, column, parent))
213 return createIndex(row, column, items.at(row));
214 return QModelIndex();
217 QVariant QListModel::data(const QModelIndex &index, int role) const
219 if (!index.isValid() || index.row() >= items.count())
221 return items.at(index.row())->data(role);
224 bool QListModel::setData(const QModelIndex &index, const QVariant &value, int role)
226 if (!index.isValid() || index.row() >= items.count())
228 items.at(index.row())->setData(role, value);
232 QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const
234 QMap<int, QVariant> roles;
235 if (!index.isValid() || index.row() >= items.count())
237 QListWidgetItem *itm = items.at(index.row());
238 for (int i = 0; i < itm->d->values.count(); ++i) {
239 roles.insert(itm->d->values.at(i).role,
240 itm->d->values.at(i).value);
245 bool QListModel::insertRows(int row, int count, const QModelIndex &parent)
247 if (count < 1 || row < 0 || row > rowCount() || parent.isValid())
250 beginInsertRows(QModelIndex(), row, row + count - 1);
251 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
252 QListWidgetItem *itm = 0;
254 for (int r = row; r < row + count; ++r) {
255 itm = new QListWidgetItem;
258 items.insert(r, itm);
265 bool QListModel::removeRows(int row, int count, const QModelIndex &parent)
267 if (count < 1 || row < 0 || (row + count) > rowCount() || parent.isValid())
270 beginRemoveRows(QModelIndex(), row, row + count - 1);
271 QListWidgetItem *itm = 0;
272 for (int r = row; r < row + count; ++r) {
273 itm = items.takeAt(row);
282 Qt::ItemFlags QListModel::flags(const QModelIndex &index) const
284 if (!index.isValid() || index.row() >= items.count() || index.model() != this)
285 return Qt::ItemIsDropEnabled; // we allow drops outside the items
286 return items.at(index.row())->flags();
289 void QListModel::sort(int column, Qt::SortOrder order)
294 emit layoutAboutToBeChanged();
296 QVector < QPair<QListWidgetItem*,int> > sorting(items.count());
297 for (int i = 0; i < items.count(); ++i) {
298 QListWidgetItem *item = items.at(i);
299 sorting[i].first = item;
300 sorting[i].second = i;
303 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
304 qSort(sorting.begin(), sorting.end(), compare);
305 QModelIndexList fromIndexes;
306 QModelIndexList toIndexes;
307 for (int r = 0; r < sorting.count(); ++r) {
308 QListWidgetItem *item = sorting.at(r).first;
309 toIndexes.append(createIndex(r, 0, item));
310 fromIndexes.append(createIndex(sorting.at(r).second, 0, sorting.at(r).first));
311 items[r] = sorting.at(r).first;
313 changePersistentIndexList(fromIndexes, toIndexes);
315 emit layoutChanged();
319 * This function assumes that all items in the model except the items that are between
320 * (inclusive) start and end are sorted.
321 * With these assumptions, this function can ensure that the model is sorted in a
322 * much more efficient way than doing a naive 'sort everything'.
323 * (provided that the range is relatively small compared to the total number of items)
325 void QListModel::ensureSorted(int column, Qt::SortOrder order, int start, int end)
330 int count = end - start + 1;
331 QVector < QPair<QListWidgetItem*,int> > sorting(count);
332 for (int i = 0; i < count; ++i) {
333 sorting[i].first = items.at(start + i);
334 sorting[i].second = start + i;
337 LessThan compare = (order == Qt::AscendingOrder ? &itemLessThan : &itemGreaterThan);
338 qSort(sorting.begin(), sorting.end(), compare);
340 QModelIndexList oldPersistentIndexes = persistentIndexList();
341 QModelIndexList newPersistentIndexes = oldPersistentIndexes;
342 QList<QListWidgetItem*> tmp = items;
343 QList<QListWidgetItem*>::iterator lit = tmp.begin();
344 bool changed = false;
345 for (int i = 0; i < count; ++i) {
346 int oldRow = sorting.at(i).second;
347 QListWidgetItem *item = tmp.takeAt(oldRow);
348 lit = sortedInsertionIterator(lit, tmp.end(), order, item);
349 int newRow = qMax(lit - tmp.begin(), 0);
350 lit = tmp.insert(lit, item);
351 if (newRow != oldRow) {
353 for (int j = i + 1; j < count; ++j) {
354 int otherRow = sorting.at(j).second;
355 if (oldRow < otherRow && newRow >= otherRow)
357 else if (oldRow > otherRow && newRow <= otherRow)
360 for (int k = 0; k < newPersistentIndexes.count(); ++k) {
361 QModelIndex pi = newPersistentIndexes.at(k);
362 int oldPersistentRow = pi.row();
363 int newPersistentRow = oldPersistentRow;
364 if (oldPersistentRow == oldRow)
365 newPersistentRow = newRow;
366 else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
367 newPersistentRow = oldPersistentRow - 1;
368 else if (oldRow > oldPersistentRow && newRow <= oldPersistentRow)
369 newPersistentRow = oldPersistentRow + 1;
370 if (newPersistentRow != oldPersistentRow)
371 newPersistentIndexes[k] = createIndex(newPersistentRow,
372 pi.column(), pi.internalPointer());
378 emit layoutAboutToBeChanged();
380 changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes);
381 emit layoutChanged();
385 bool QListModel::itemLessThan(const QPair<QListWidgetItem*,int> &left,
386 const QPair<QListWidgetItem*,int> &right)
388 return (*left.first) < (*right.first);
391 bool QListModel::itemGreaterThan(const QPair<QListWidgetItem*,int> &left,
392 const QPair<QListWidgetItem*,int> &right)
394 return (*right.first) < (*left.first);
397 QList<QListWidgetItem*>::iterator QListModel::sortedInsertionIterator(
398 const QList<QListWidgetItem*>::iterator &begin,
399 const QList<QListWidgetItem*>::iterator &end,
400 Qt::SortOrder order, QListWidgetItem *item)
402 if (order == Qt::AscendingOrder)
403 return qLowerBound(begin, end, item, QListModelLessThan());
404 return qLowerBound(begin, end, item, QListModelGreaterThan());
407 void QListModel::itemChanged(QListWidgetItem *item)
409 QModelIndex idx = index(item);
410 emit dataChanged(idx, idx);
413 QStringList QListModel::mimeTypes() const
415 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
416 return view->mimeTypes();
419 QMimeData *QListModel::internalMimeData() const
421 return QAbstractItemModel::mimeData(cachedIndexes);
424 QMimeData *QListModel::mimeData(const QModelIndexList &indexes) const
426 QList<QListWidgetItem*> itemlist;
427 for (int i = 0; i < indexes.count(); ++i)
428 itemlist << at(indexes.at(i).row());
429 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
431 cachedIndexes = indexes;
432 QMimeData *mimeData = view->mimeData(itemlist);
433 cachedIndexes.clear();
437 #ifndef QT_NO_DRAGANDDROP
438 bool QListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
439 int row, int column, const QModelIndex &index)
442 QListWidget *view = qobject_cast<QListWidget*>(QObject::parent());
448 return view->dropMimeData(row, data, action);
451 Qt::DropActions QListModel::supportedDropActions() const
453 const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent());
454 return view->supportedDropActions();
456 #endif // QT_NO_DRAGANDDROP
459 \class QListWidgetItem
460 \brief The QListWidgetItem class provides an item for use with the
461 QListWidget item view class.
466 A QListWidgetItem represents a single item in a QListWidget. Each item can
467 hold several pieces of information, and will display them appropriately.
469 The item view convenience classes use a classic item-based interface rather
470 than a pure model/view approach. For a more flexible list view widget,
471 consider using the QListView class with a standard model.
473 List items can be inserted automatically into a list, when they are
474 constructed, by specifying the list widget:
476 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 2
478 Alternatively, list items can also be created without a parent widget, and
479 later inserted into a list using QListWidget::insertItem().
481 List items are typically used to display text() and an icon(). These are
482 set with the setText() and setIcon() functions. The appearance of the text
483 can be customized with setFont(), setForeground(), and setBackground().
484 Text in list items can be aligned using the setTextAlignment() function.
485 Tooltips, status tips and "What's This?" help can be added to list items
486 with setToolTip(), setStatusTip(), and setWhatsThis().
488 By default, items are enabled, selectable, checkable, and can be the source
489 of drag and drop operations.
491 Each item's flags can be changed by calling setFlags() with the appropriate
492 value (see Qt::ItemFlags). Checkable items can be checked, unchecked and
493 partially checked with the setCheckState() function. The corresponding
494 checkState() function indicates the item's current check state.
496 The isHidden() function can be used to determine whether the item is
497 hidden. To hide an item, use setHidden().
500 \section1 Subclassing
502 When subclassing QListWidgetItem to provide custom items, it is possible to
503 define new types for them enabling them to be distinguished from standard
504 items. For subclasses that require this feature, ensure that you call the
505 base class constructor with a new type value equal to or greater than
506 \l UserType, within \e your constructor.
508 \sa QListWidget, {Model/View Programming}, QTreeWidgetItem, QTableWidgetItem
512 \enum QListWidgetItem::ItemType
514 This enum describes the types that are used to describe list widget items.
516 \value Type The default type for list widget items.
517 \value UserType The minimum value for custom types. Values below UserType are
520 You can define new user types in QListWidgetItem subclasses to ensure that
521 custom items are treated specially.
527 \fn int QListWidgetItem::type() const
529 Returns the type passed to the QListWidgetItem constructor.
533 \fn QListWidget *QListWidgetItem::listWidget() const
535 Returns the list widget containing the item.
539 \fn void QListWidgetItem::setSelected(bool select)
542 Sets the selected state of the item to \a select.
548 \fn bool QListWidgetItem::isSelected() const
551 Returns true if the item is selected; otherwise returns false.
557 \fn void QListWidgetItem::setHidden(bool hide)
560 Hides the item if \a hide is true; otherwise shows the item.
566 \fn bool QListWidgetItem::isHidden() const
569 Returns true if the item is hidden; otherwise returns false.
575 \fn QListWidgetItem::QListWidgetItem(QListWidget *parent, int type)
577 Constructs an empty list widget item of the specified \a type with the
578 given \a parent. If \a parent is not specified, the item will need to be
579 inserted into a list widget with QListWidget::insertItem().
581 This constructor inserts the item into the model of the parent that is
582 passed to the constructor. If the model is sorted then the behavior of the
583 insert is undetermined since the model will call the \c '<' operator method
584 on the item which, at this point, is not yet constructed. To avoid the
585 undetermined behavior, we recommend not to specify the parent and use
586 QListWidget::insertItem() instead.
590 QListWidgetItem::QListWidgetItem(QListWidget *view, int type)
591 : rtti(type), view(view), d(new QListWidgetItemPrivate(this)),
592 itemFlags(Qt::ItemIsSelectable
593 |Qt::ItemIsUserCheckable
595 |Qt::ItemIsDragEnabled)
597 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
598 model->insert(model->rowCount(), this);
602 \fn QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *parent, int type)
604 Constructs an empty list widget item of the specified \a type with the
605 given \a text and \a parent. If the parent is not specified, the item will
606 need to be inserted into a list widget with QListWidget::insertItem().
608 This constructor inserts the item into the model of the parent that is
609 passed to the constructor. If the model is sorted then the behavior of the
610 insert is undetermined since the model will call the \c '<' operator method
611 on the item which, at this point, is not yet constructed. To avoid the
612 undetermined behavior, we recommend not to specify the parent and use
613 QListWidget::insertItem() instead.
617 QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view, int type)
618 : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
619 itemFlags(Qt::ItemIsSelectable
620 |Qt::ItemIsUserCheckable
622 |Qt::ItemIsDragEnabled)
624 setData(Qt::DisplayRole, text);
626 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
627 model->insert(model->rowCount(), this);
631 \fn QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent, int type)
633 Constructs an empty list widget item of the specified \a type with the
634 given \a icon, \a text and \a parent. If the parent is not specified, the
635 item will need to be inserted into a list widget with
636 QListWidget::insertItem().
638 This constructor inserts the item into the model of the parent that is
639 passed to the constructor. If the model is sorted then the behavior of the
640 insert is undetermined since the model will call the \c '<' operator method
641 on the item which, at this point, is not yet constructed. To avoid the
642 undetermined behavior, we recommend not to specify the parent and use
643 QListWidget::insertItem() instead.
647 QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text,
648 QListWidget *view, int type)
649 : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
650 itemFlags(Qt::ItemIsSelectable
651 |Qt::ItemIsUserCheckable
653 |Qt::ItemIsDragEnabled)
655 setData(Qt::DisplayRole, text);
656 setData(Qt::DecorationRole, icon);
658 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
659 model->insert(model->rowCount(), this);
663 Destroys the list item.
665 QListWidgetItem::~QListWidgetItem()
667 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
673 Creates an exact copy of the item.
675 QListWidgetItem *QListWidgetItem::clone() const
677 return new QListWidgetItem(*this);
681 Sets the data for a given \a role to the given \a value. Reimplement this
682 function if you need extra roles or special behavior for certain roles.
684 \sa Qt::ItemDataRole, data()
686 void QListWidgetItem::setData(int role, const QVariant &value)
689 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
690 for (int i = 0; i < d->values.count(); ++i) {
691 if (d->values.at(i).role == role) {
692 if (d->values.at(i).value == value)
694 d->values[i].value = value;
700 d->values.append(QWidgetItemData(role, value));
701 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
702 model->itemChanged(this);
706 Returns the item's data for a given \a role. Reimplement this function if
707 you need extra roles or special behavior for certain roles.
709 \sa Qt::ItemDataRole, setData()
711 QVariant QListWidgetItem::data(int role) const
713 role = (role == Qt::EditRole ? Qt::DisplayRole : role);
714 for (int i = 0; i < d->values.count(); ++i)
715 if (d->values.at(i).role == role)
716 return d->values.at(i).value;
721 Returns true if this item's text is less then \a other item's text;
722 otherwise returns false.
724 bool QListWidgetItem::operator<(const QListWidgetItem &other) const
726 const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole);
727 return QAbstractItemModelPrivate::variantLessThan(v1, v2);
730 #ifndef QT_NO_DATASTREAM
733 Reads the item from stream \a in.
737 void QListWidgetItem::read(QDataStream &in)
743 Writes the item to stream \a out.
747 void QListWidgetItem::write(QDataStream &out) const
751 #endif // QT_NO_DATASTREAM
756 Constructs a copy of \a other. Note that type() and listWidget() are not
759 This function is useful when reimplementing clone().
763 QListWidgetItem::QListWidgetItem(const QListWidgetItem &other)
764 : rtti(Type), view(0),
765 d(new QListWidgetItemPrivate(this)),
766 itemFlags(other.itemFlags)
768 d->values = other.d->values;
772 Assigns \a other's data and flags to this item. Note that type() and
773 listWidget() are not copied.
775 This function is useful when reimplementing clone().
779 QListWidgetItem &QListWidgetItem::operator=(const QListWidgetItem &other)
781 d->values = other.d->values;
782 itemFlags = other.itemFlags;
786 #ifndef QT_NO_DATASTREAM
789 \relates QListWidgetItem
791 Writes the list widget item \a item to stream \a out.
793 This operator uses QListWidgetItem::write().
795 \sa {Serializing Qt Data Types}
797 QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item)
804 \relates QListWidgetItem
806 Reads a list widget item from stream \a in into \a item.
808 This operator uses QListWidgetItem::read().
810 \sa {Serializing Qt Data Types}
812 QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
818 #endif // QT_NO_DATASTREAM
821 \fn Qt::ItemFlags QListWidgetItem::flags() const
823 Returns the item flags for this item (see \l{Qt::ItemFlags}).
827 \fn QString QListWidgetItem::text() const
829 Returns the list item's text.
835 \fn QIcon QListWidgetItem::icon() const
837 Returns the list item's icon.
839 \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}
843 \fn QString QListWidgetItem::statusTip() const
845 Returns the list item's status tip.
851 \fn QString QListWidgetItem::toolTip() const
853 Returns the list item's tooltip.
855 \sa setToolTip() statusTip() whatsThis()
859 \fn QString QListWidgetItem::whatsThis() const
861 Returns the list item's "What's This?" help text.
863 \sa setWhatsThis() statusTip() toolTip()
867 \fn QFont QListWidgetItem::font() const
869 Returns the font used to display this list item's text.
873 \fn int QListWidgetItem::textAlignment() const
875 Returns the text alignment for the list item.
877 \sa Qt::AlignmentFlag
881 \fn QColor QListWidgetItem::backgroundColor() const
884 This function is deprecated. Use background() instead.
888 \fn QBrush QListWidgetItem::background() const
891 Returns the brush used to display the list item's background.
893 \sa setBackground() foreground()
897 \fn QColor QListWidgetItem::textColor() const
900 Returns the color used to display the list item's text.
902 This function is deprecated. Use foreground() instead.
906 \fn QBrush QListWidgetItem::foreground() const
909 Returns the brush used to display the list item's foreground (e.g. text).
911 \sa setForeground() background()
915 \fn Qt::CheckState QListWidgetItem::checkState() const
917 Returns the checked state of the list item (see \l{Qt::CheckState}).
923 \fn QSize QListWidgetItem::sizeHint() const
926 Returns the size hint set for the list item.
930 \fn void QListWidgetItem::setSizeHint(const QSize &size)
933 Sets the size hint for the list item to be \a size. If no size hint is set,
934 the item delegate will compute the size hint based on the item data.
938 \fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
940 Sets the item flags for the list item to \a flags.
944 void QListWidgetItem::setFlags(Qt::ItemFlags aflags) {
946 if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
947 model->itemChanged(this);
952 \fn void QListWidgetItem::setText(const QString &text)
954 Sets the text for the list widget item's to the given \a text.
960 \fn void QListWidgetItem::setIcon(const QIcon &icon)
962 Sets the icon for the list item to the given \a icon.
964 \sa icon(), text(), {QAbstractItemView::iconSize}{iconSize}
968 \fn void QListWidgetItem::setStatusTip(const QString &statusTip)
970 Sets the status tip for the list item to the text specified by
971 \a statusTip. QListWidget mouseTracking needs to be enabled for this
974 \sa statusTip(), setToolTip(), setWhatsThis(), QWidget::setMouseTracking()
978 \fn void QListWidgetItem::setToolTip(const QString &toolTip)
980 Sets the tooltip for the list item to the text specified by \a toolTip.
982 \sa toolTip(), setStatusTip(), setWhatsThis()
986 \fn void QListWidgetItem::setWhatsThis(const QString &whatsThis)
988 Sets the "What's This?" help for the list item to the text specified by
991 \sa whatsThis(), setStatusTip(), setToolTip()
995 \fn void QListWidgetItem::setFont(const QFont &font)
997 Sets the font used when painting the item to the given \a font.
1001 \fn void QListWidgetItem::setTextAlignment(int alignment)
1003 Sets the list item's text alignment to \a alignment.
1005 \sa Qt::AlignmentFlag
1009 \fn void QListWidgetItem::setBackgroundColor(const QColor &color)
1012 This function is deprecated. Use setBackground() instead.
1016 \fn void QListWidgetItem::setBackground(const QBrush &brush)
1019 Sets the background brush of the list item to the given \a brush.
1021 \sa background() setForeground()
1025 \fn void QListWidgetItem::setTextColor(const QColor &color)
1028 This function is deprecated. Use setForeground() instead.
1032 \fn void QListWidgetItem::setForeground(const QBrush &brush)
1035 Sets the foreground brush of the list item to the given \a brush.
1037 \sa foreground() setBackground()
1041 \fn void QListWidgetItem::setCheckState(Qt::CheckState state)
1043 Sets the check state of the list item to \a state.
1048 void QListWidgetPrivate::setup()
1051 q->QListView::setModel(new QListModel(q));
1053 QObject::connect(q, SIGNAL(pressed(QModelIndex)), q, SLOT(_q_emitItemPressed(QModelIndex)));
1054 QObject::connect(q, SIGNAL(clicked(QModelIndex)), q, SLOT(_q_emitItemClicked(QModelIndex)));
1055 QObject::connect(q, SIGNAL(doubleClicked(QModelIndex)),
1056 q, SLOT(_q_emitItemDoubleClicked(QModelIndex)));
1057 QObject::connect(q, SIGNAL(activated(QModelIndex)),
1058 q, SLOT(_q_emitItemActivated(QModelIndex)));
1059 QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex)));
1060 QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1061 q, SLOT(_q_emitItemChanged(QModelIndex)));
1062 QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1063 q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex)));
1064 QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
1065 q, SIGNAL(itemSelectionChanged()));
1066 QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1067 q, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
1068 QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));
1071 void QListWidgetPrivate::_q_emitItemPressed(const QModelIndex &index)
1074 emit q->itemPressed(listModel()->at(index.row()));
1077 void QListWidgetPrivate::_q_emitItemClicked(const QModelIndex &index)
1080 emit q->itemClicked(listModel()->at(index.row()));
1083 void QListWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index)
1086 emit q->itemDoubleClicked(listModel()->at(index.row()));
1089 void QListWidgetPrivate::_q_emitItemActivated(const QModelIndex &index)
1092 emit q->itemActivated(listModel()->at(index.row()));
1095 void QListWidgetPrivate::_q_emitItemEntered(const QModelIndex &index)
1098 emit q->itemEntered(listModel()->at(index.row()));
1101 void QListWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)
1104 emit q->itemChanged(listModel()->at(index.row()));
1107 void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t,
1108 const QModelIndex &previous)
1111 QPersistentModelIndex persistentCurrent = current;
1112 QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row());
1113 emit q->currentItemChanged(currentItem, listModel()->at(previous.row()));
1115 //persistentCurrent is invalid if something changed the model in response
1116 //to the currentItemChanged signal emission and the item was removed
1117 if (!persistentCurrent.isValid()) {
1121 emit q->currentTextChanged(currentItem ? currentItem->text() : QString());
1122 emit q->currentRowChanged(persistentCurrent.row());
1125 void QListWidgetPrivate::_q_sort()
1128 model->sort(0, sortOrder);
1131 void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
1132 const QModelIndex &bottomRight)
1134 if (sortingEnabled && topLeft.isValid() && bottomRight.isValid())
1135 listModel()->ensureSorted(topLeft.column(), sortOrder,
1136 topLeft.row(), bottomRight.row());
1141 \brief The QListWidget class provides an item-based list widget.
1146 QListWidget is a convenience class that provides a list view similar to the
1147 one supplied by QListView, but with a classic item-based interface for
1148 adding and removing items. QListWidget uses an internal model to manage
1149 each QListWidgetItem in the list.
1151 For a more flexible list view widget, use the QListView class with a
1154 List widgets are constructed in the same way as other widgets:
1156 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 0
1158 The selectionMode() of a list widget determines how many of the items in
1159 the list can be selected at the same time, and whether complex selections
1160 of items can be created. This can be set with the setSelectionMode()
1163 There are two ways to add items to the list: they can be constructed with
1164 the list widget as their parent widget, or they can be constructed with no
1165 parent widget and added to the list later. If a list widget already exists
1166 when the items are constructed, the first method is easier to use:
1168 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 1
1170 If you need to insert a new item into the list at a particular position, it
1171 is more required to construct the item without a parent widget and use the
1172 insertItem() function to place it within the list. The list widget will
1173 take ownership of the item.
1175 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 6
1176 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 7
1178 For multiple items, insertItems() can be used instead. The number of items
1179 in the list is found with the count() function. To remove items from the
1180 list, use takeItem().
1182 The current item in the list can be found with currentItem(), and changed
1183 with setCurrentItem(). The user can also change the current item by
1184 navigating with the keyboard or clicking on a different item. When the
1185 current item changes, the currentItemChanged() signal is emitted with the
1186 new current item and the item that was previously current.
1189 \row \o \inlineimage windowsxp-listview.png Screenshot of a Windows XP style list widget
1190 \o \inlineimage macintosh-listview.png Screenshot of a Macintosh style table widget
1191 \o \inlineimage plastique-listview.png Screenshot of a Plastique style table widget
1192 \row \o A \l{Windows XP Style Widget Gallery}{Windows XP style} list widget.
1193 \o A \l{Macintosh Style Widget Gallery}{Macintosh style} list widget.
1194 \o A \l{Plastique Style Widget Gallery}{Plastique style} list widget.
1197 \sa QListWidgetItem, QListView, QTreeView, {Model/View Programming},
1198 {Config Dialog Example}
1202 \fn void QListWidget::addItem(QListWidgetItem *item)
1204 Inserts the \a item at the end of the list widget.
1206 \warning A QListWidgetItem can only be added to a QListWidget once. Adding
1207 the same QListWidgetItem multiple times to a QListWidget will result in
1214 \fn void QListWidget::addItem(const QString &label)
1216 Inserts an item with the text \a label at the end of the list widget.
1220 \fn void QListWidget::addItems(const QStringList &labels)
1222 Inserts items with the text \a labels at the end of the list widget.
1228 \fn void QListWidget::itemPressed(QListWidgetItem *item)
1230 This signal is emitted with the specified \a item when a mouse button is
1231 pressed on an item in the widget.
1233 \sa itemClicked(), itemDoubleClicked()
1237 \fn void QListWidget::itemClicked(QListWidgetItem *item)
1239 This signal is emitted with the specified \a item when a mouse button is
1240 clicked on an item in the widget.
1242 \sa itemPressed(), itemDoubleClicked()
1246 \fn void QListWidget::itemDoubleClicked(QListWidgetItem *item)
1248 This signal is emitted with the specified \a item when a mouse button is
1249 double clicked on an item in the widget.
1251 \sa itemClicked(), itemPressed()
1255 \fn void QListWidget::itemActivated(QListWidgetItem *item)
1257 This signal is emitted when the \a item is activated. The \a item is
1258 activated when the user clicks or double clicks on it, depending on the
1259 system configuration. It is also activated when the user presses the
1260 activation key (on Windows and X11 this is the \gui Return key, on Mac OS
1261 X it is \key{Ctrl+0}).
1265 \fn void QListWidget::itemEntered(QListWidgetItem *item)
1267 This signal is emitted when the mouse cursor enters an item. The \a item is
1268 the item entered. This signal is only emitted when mouseTracking is turned
1269 on, or when a mouse button is pressed while moving into an item.
1271 \sa QWidget::setMouseTracking()
1275 \fn void QListWidget::itemChanged(QListWidgetItem *item)
1277 This signal is emitted whenever the data of \a item has changed.
1281 \fn void QListWidget::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
1283 This signal is emitted whenever the current item changes.
1285 \a previous is the item that previously had the focus; \a current is the
1290 \fn void QListWidget::currentTextChanged(const QString ¤tText)
1292 This signal is emitted whenever the current item changes.
1294 \a currentText is the text data in the current item. If there is no current
1295 item, the \a currentText is invalid.
1299 \fn void QListWidget::currentRowChanged(int currentRow)
1301 This signal is emitted whenever the current item changes.
1303 \a currentRow is the row of the current item. If there is no current item,
1304 the \a currentRow is -1.
1308 \fn void QListWidget::itemSelectionChanged()
1310 This signal is emitted whenever the selection changes.
1312 \sa selectedItems(), QListWidgetItem::isSelected(), currentItemChanged()
1318 \fn void QListWidget::removeItemWidget(QListWidgetItem *item)
1320 Removes the widget set on the given \a item.
1324 Constructs an empty QListWidget with the given \a parent.
1327 QListWidget::QListWidget(QWidget *parent)
1328 : QListView(*new QListWidgetPrivate(), parent)
1335 Destroys the list widget and all its items.
1338 QListWidget::~QListWidget()
1343 Returns the item that occupies the given \a row in the list if one has been
1344 set; otherwise returns 0.
1349 QListWidgetItem *QListWidget::item(int row) const
1351 Q_D(const QListWidget);
1352 if (row < 0 || row >= d->model->rowCount())
1354 return d->listModel()->at(row);
1358 Returns the row containing the given \a item.
1363 int QListWidget::row(const QListWidgetItem *item) const
1365 Q_D(const QListWidget);
1366 return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row();
1371 Inserts the \a item at the position in the list given by \a row.
1376 void QListWidget::insertItem(int row, QListWidgetItem *item)
1379 if (item && !item->view)
1380 d->listModel()->insert(row, item);
1384 Inserts an item with the text \a label in the list widget at the position
1390 void QListWidget::insertItem(int row, const QString &label)
1393 d->listModel()->insert(row, new QListWidgetItem(label));
1397 Inserts items from the list of \a labels into the list, starting at the
1400 \sa insertItem(), addItem()
1403 void QListWidget::insertItems(int row, const QStringList &labels)
1406 d->listModel()->insert(row, labels);
1410 Removes and returns the item from the given \a row in the list widget;
1411 otherwise returns 0.
1413 Items removed from a list widget will not be managed by Qt, and will need
1414 to be deleted manually.
1416 \sa insertItem(), addItem()
1419 QListWidgetItem *QListWidget::takeItem(int row)
1422 if (row < 0 || row >= d->model->rowCount())
1424 return d->listModel()->take(row);
1428 \property QListWidget::count
1429 \brief the number of items in the list including any hidden items.
1432 int QListWidget::count() const
1434 Q_D(const QListWidget);
1435 return d->model->rowCount();
1439 Returns the current item.
1441 QListWidgetItem *QListWidget::currentItem() const
1443 Q_D(const QListWidget);
1444 return d->listModel()->at(currentIndex().row());
1449 Sets the current item to \a item.
1451 Unless the selection mode is \l{QAbstractItemView::}{NoSelection},
1452 the item is also be selected.
1454 void QListWidget::setCurrentItem(QListWidgetItem *item)
1456 setCurrentRow(row(item));
1461 Set the current item to \a item, using the given \a command.
1463 void QListWidget::setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command)
1465 setCurrentRow(row(item), command);
1469 \property QListWidget::currentRow
1470 \brief the row of the current item.
1472 Depending on the current selection mode, the row may also be selected.
1475 int QListWidget::currentRow() const
1477 return currentIndex().row();
1480 void QListWidget::setCurrentRow(int row)
1483 QModelIndex index = d->listModel()->index(row);
1484 if (d->selectionMode == SingleSelection)
1485 selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
1486 else if (d->selectionMode == NoSelection)
1487 selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
1489 selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
1495 Sets the current row to be the given \a row, using the given \a command,
1497 void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
1500 d->selectionModel->setCurrentIndex(d->listModel()->index(row), command);
1504 Returns a pointer to the item at the coordinates \a p. The coordinates
1505 are relative to the list widget's \l{QAbstractScrollArea::}{viewport()}.
1508 QListWidgetItem *QListWidget::itemAt(const QPoint &p) const
1510 Q_D(const QListWidget);
1511 return d->listModel()->at(indexAt(p).row());
1516 \fn QListWidgetItem *QListWidget::itemAt(int x, int y) const
1519 Returns a pointer to the item at the coordinates (\a x, \a y).
1520 The coordinates are relative to the list widget's
1521 \l{QAbstractScrollArea::}{viewport()}.
1527 Returns the rectangle on the viewport occupied by the item at \a item.
1529 QRect QListWidget::visualItemRect(const QListWidgetItem *item) const
1531 Q_D(const QListWidget);
1532 QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1533 return visualRect(index);
1537 Sorts all the items in the list widget according to the specified \a order.
1539 void QListWidget::sortItems(Qt::SortOrder order)
1542 d->sortOrder = order;
1543 d->listModel()->sort(0, order);
1548 \property QListWidget::sortingEnabled
1549 \brief whether sorting is enabled
1551 If this property is true, sorting is enabled for the list; if the property
1552 is false, sorting is not enabled.
1554 The default value is false.
1556 void QListWidget::setSortingEnabled(bool enable)
1559 d->sortingEnabled = enable;
1562 bool QListWidget::isSortingEnabled() const
1564 Q_D(const QListWidget);
1565 return d->sortingEnabled;
1571 Qt::SortOrder QListWidget::sortOrder() const
1573 Q_D(const QListWidget);
1574 return d->sortOrder;
1578 Starts editing the \a item if it is editable.
1581 void QListWidget::editItem(QListWidgetItem *item)
1584 edit(d->listModel()->index(item));
1588 Opens an editor for the given \a item. The editor remains open after
1591 \sa closePersistentEditor()
1593 void QListWidget::openPersistentEditor(QListWidgetItem *item)
1596 QModelIndex index = d->listModel()->index(item);
1597 QAbstractItemView::openPersistentEditor(index);
1601 Closes the persistent editor for the given \a item.
1603 \sa openPersistentEditor()
1605 void QListWidget::closePersistentEditor(QListWidgetItem *item)
1608 QModelIndex index = d->listModel()->index(item);
1609 QAbstractItemView::closePersistentEditor(index);
1615 Returns the widget displayed in the given \a item.
1617 QWidget *QListWidget::itemWidget(QListWidgetItem *item) const
1619 Q_D(const QListWidget);
1620 QModelIndex index = d->listModel()->index(item);
1621 return QAbstractItemView::indexWidget(index);
1627 Sets the \a widget to be displayed in the give \a item.
1629 This function should only be used to display static content in the place of
1630 a list widget item. If you want to display custom dynamic content or
1631 implement a custom editor widget, use QListView and subclass QItemDelegate
1634 \sa {Delegate Classes}
1636 void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
1639 QModelIndex index = d->listModel()->index(item);
1640 QAbstractItemView::setIndexWidget(index, widget);
1644 Returns true if \a item is selected; otherwise returns false.
1648 This function is deprecated. Use QListWidgetItem::isSelected() instead.
1650 bool QListWidget::isItemSelected(const QListWidgetItem *item) const
1652 Q_D(const QListWidget);
1653 QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1654 return selectionModel()->isSelected(index);
1658 Selects or deselects the given \a item depending on whether \a select is
1663 This function is deprecated. Use QListWidgetItem::setSelected() instead.
1665 void QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
1668 QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1670 if (d->selectionMode == SingleSelection) {
1671 selectionModel()->select(index, select
1672 ? QItemSelectionModel::ClearAndSelect
1673 : QItemSelectionModel::Deselect);
1674 } else if (d->selectionMode != NoSelection) {
1675 selectionModel()->select(index, select
1676 ? QItemSelectionModel::Select
1677 : QItemSelectionModel::Deselect);
1683 Returns a list of all selected items in the list widget.
1686 QList<QListWidgetItem*> QListWidget::selectedItems() const
1688 Q_D(const QListWidget);
1689 QModelIndexList indexes = selectionModel()->selectedIndexes();
1690 QList<QListWidgetItem*> items;
1691 for (int i = 0; i < indexes.count(); ++i)
1692 items.append(d->listModel()->at(indexes.at(i).row()));
1697 Finds items with the text that matches the string \a text using the given
1701 QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const
1703 Q_D(const QListWidget);
1704 QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()),
1705 Qt::DisplayRole, text, -1, flags);
1706 QList<QListWidgetItem*> items;
1707 for (int i = 0; i < indexes.size(); ++i)
1708 items.append(d->listModel()->at(indexes.at(i).row()));
1713 Returns true if the \a item is explicitly hidden; otherwise returns false.
1717 This function is deprecated. Use QListWidgetItem::isHidden() instead.
1719 bool QListWidget::isItemHidden(const QListWidgetItem *item) const
1721 return isRowHidden(row(item));
1725 If \a hide is true, the \a item will be hidden; otherwise it will be shown.
1729 This function is deprecated. Use QListWidgetItem::setHidden() instead.
1731 void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide)
1733 setRowHidden(row(item), hide);
1737 Scrolls the view if necessary to ensure that the \a item is visible.
1739 \a hint specifies where the \a item should be located after the operation.
1742 void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint)
1745 QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1746 QListView::scrollTo(index, hint);
1750 Removes all items and selections in the view.
1752 \warning All items will be permanently deleted.
1754 void QListWidget::clear()
1757 selectionModel()->clear();
1758 d->listModel()->clear();
1762 Returns a list of MIME types that can be used to describe a list of
1767 QStringList QListWidget::mimeTypes() const
1769 return d_func()->listModel()->QAbstractListModel::mimeTypes();
1773 Returns an object that contains a serialized description of the specified
1774 \a items. The format used to describe the items is obtained from the
1775 mimeTypes() function.
1777 If the list of items is empty, 0 is returned instead of a serialized empty
1780 QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*>) const
1782 return d_func()->listModel()->internalMimeData();
1785 #ifndef QT_NO_DRAGANDDROP
1787 Handles \a data supplied by an external drag and drop operation that ended
1788 with the given \a action in the given \a index. Returns true if \a data and
1789 \a action can be handled by the model; otherwise returns false.
1791 \sa supportedDropActions()
1793 bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action)
1798 if (dropIndicatorPosition() == QAbstractItemView::OnItem) {
1799 // QAbstractListModel::dropMimeData will overwrite on the index if row == -1 and column == -1
1800 idx = model()->index(row, column);
1804 return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx);
1808 void QListWidget::dropEvent(QDropEvent *event) {
1810 if (event->source() == this && d->movement != Static) {
1811 QListView::dropEvent(event);
1815 if (event->source() == this && (event->dropAction() == Qt::MoveAction ||
1816 dragDropMode() == QAbstractItemView::InternalMove)) {
1817 QModelIndex topIndex;
1820 if (d->dropOn(event, &row, &col, &topIndex)) {
1821 QList<QModelIndex> selIndexes = selectedIndexes();
1822 QList<QPersistentModelIndex> persIndexes;
1823 for (int i = 0; i < selIndexes.count(); i++)
1824 persIndexes.append(selIndexes.at(i));
1826 if (persIndexes.contains(topIndex))
1828 qSort(persIndexes); // The dropped items will remain in the same visual order.
1830 QPersistentModelIndex dropRow = model()->index(row, col, topIndex);
1832 int r = row == -1 ? count() : (dropRow.row() >= 0 ? dropRow.row() : row);
1833 for (int i = 0; i < persIndexes.count(); ++i) {
1834 const QPersistentModelIndex &pIndex = persIndexes.at(i);
1835 d->listModel()->move(pIndex.row(), r);
1836 r = pIndex.row() + 1; // Dropped items are inserted contiguously and in the right order.
1840 // Don't want QAbstractItemView to delete it because it was "moved" we already did it
1841 event->setDropAction(Qt::CopyAction);
1845 QListView::dropEvent(event);
1849 Returns the drop actions supported by this view.
1853 Qt::DropActions QListWidget::supportedDropActions() const
1855 Q_D(const QListWidget);
1856 return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
1858 #endif // QT_NO_DRAGANDDROP
1861 Returns a list of pointers to the items contained in the \a data object. If
1862 the object was not created by a QListWidget in the same process, the list
1865 QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const
1867 const QListWidgetMimeData *lwd = qobject_cast<const QListWidgetMimeData*>(data);
1870 return QList<QListWidgetItem*>();
1874 Returns the QModelIndex assocated with the given \a item.
1877 QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const
1879 Q_D(const QListWidget);
1880 return d->listModel()->index(item);
1884 Returns a pointer to the QListWidgetItem assocated with the given \a index.
1887 QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const
1889 Q_D(const QListWidget);
1890 if (d->isIndexValid(index))
1891 return d->listModel()->at(index.row());
1898 void QListWidget::setModel(QAbstractItemModel * /*model*/)
1900 Q_ASSERT(!"QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");
1906 bool QListWidget::event(QEvent *e)
1908 return QListView::event(e);
1913 #include "moc_qlistwidget.cpp"
1915 #endif // QT_NO_LISTWIDGET