1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtGui module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
448
448
\ingroup model-view
450
QListWidgetItem is used to represent items in a list provided by the
451
QListWidget class. Each item can hold several pieces of information,
452
and will display these appropriately.
454
The item view convenience classes use a classic item-based interface
455
rather than a pure model/view approach. For a more flexible list view
456
widget, consider using the QListView class with a standard model.
458
List items can be automatically inserted into a list when they are
459
constructed by specifying the list widget:
450
A QListWidgetItem represents a single item in a QListWidget. Each item can
451
hold several pieces of information, and will display them appropriately.
453
The item view convenience classes use a classic item-based interface rather
454
than a pure model/view approach. For a more flexible list view widget,
455
consider using the QListView class with a standard model.
457
List items can be inserted automatically into a list, when they are
458
constructed, by specifying the list widget:
461
460
\snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 2
463
They can also be created without a parent widget, and later inserted into
464
a list (see \l{QListWidget::insertItem()}).
462
Alternatively, list items can also be created without a parent widget, and
463
later inserted into a list using QListWidget::insertItem().
466
465
List items are typically used to display text() and an icon(). These are
467
466
set with the setText() and setIcon() functions. The appearance of the text
471
470
with setToolTip(), setStatusTip(), and setWhatsThis().
473
472
By default, items are enabled, selectable, checkable, and can be the source
474
of a drag and drop operation.
473
of drag and drop operations.
475
475
Each item's flags can be changed by calling setFlags() with the appropriate
476
value (see \l{Qt::ItemFlags}). Checkable items can be checked, unchecked and
476
value (see Qt::ItemFlags). Checkable items can be checked, unchecked and
477
477
partially checked with the setCheckState() function. The corresponding
478
checkState() function indicates what check state the item currently has.
480
The isHidden() function can be used to determine whether the
481
item is hidden. Items can be hidden with setHidden().
478
checkState() function indicates the item's current check state.
480
The isHidden() function can be used to determine whether the item is
481
hidden. To hide an item, use setHidden().
483
484
\section1 Subclassing
485
486
When subclassing QListWidgetItem to provide custom items, it is possible to
486
define new types for them so that they can be distinguished from standard
487
items. The constructors for subclasses that require this feature need to
488
call the base class constructor with a new type value equal to or greater
487
define new types for them enabling them to be distinguished from standard
488
items. For subclasses that require this feature, ensure that you call the
489
base class constructor with a new type value equal to or greater than
490
\l UserType, within \e your constructor.
491
492
\sa QListWidget, {Model/View Programming}, QTreeWidgetItem, QTableWidgetItem
516
517
\fn QListWidget *QListWidgetItem::listWidget() const
518
Returns the list widget that contains the item.
522
\fn void QListWidgetItem::setSelected(bool select)
525
Sets the selected state of the item to \a select.
531
\fn bool QListWidgetItem::isSelected() const
534
Returns true if the item is selected, otherwise returns false.
540
\fn void QListWidgetItem::setHidden(bool hide)
543
Hides the item if \a hide is true, otherwise shows the item.
549
\fn bool QListWidgetItem::isHidden() const
552
Returns true if the item is hidden, otherwise returns false.
519
Returns the list widget containing the item.
523
\fn void QListWidgetItem::setSelected(bool select)
526
Sets the selected state of the item to \a select.
532
\fn bool QListWidgetItem::isSelected() const
535
Returns true if the item is selected; otherwise returns false.
541
\fn void QListWidgetItem::setHidden(bool hide)
544
Hides the item if \a hide is true; otherwise shows the item.
550
\fn bool QListWidgetItem::isHidden() const
553
Returns true if the item is hidden; otherwise returns false.
558
559
\fn QListWidgetItem::QListWidgetItem(QListWidget *parent, int type)
560
561
Constructs an empty list widget item of the specified \a type with the
562
If the parent is not specified, the item will need to be inserted into a
563
list widget with QListWidget::insertItem().
562
given \a parent. If \a parent is not specified, the item will need to be
563
inserted into a list widget with QListWidget::insertItem().
565
This constructor inserts the item into the model of the parent that is
566
passed to the constructor. If the model is sorted then the behavior of the
567
insert is undetermined since the model will call the \c '<' operator method
568
on the item which, at this point, is not yet constructed. To avoid the
569
undetermined behavior, we recommend not to specify the parent and use
570
QListWidget::insertItem() instead.
579
586
\fn QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *parent, int type)
581
588
Constructs an empty list widget item of the specified \a type with the
582
given \a text and \a parent.
583
If the parent is not specified, the item will need to be inserted into a
584
list widget with QListWidget::insertItem().
589
given \a text and \a parent. If the parent is not specified, the item will
590
need to be inserted into a list widget with QListWidget::insertItem().
592
This constructor inserts the item into the model of the parent that is
593
passed to the constructor. If the model is sorted then the behavior of the
594
insert is undetermined since the model will call the \c '<' operator method
595
on the item which, at this point, is not yet constructed. To avoid the
596
undetermined behavior, we recommend not to specify the parent and use
597
QListWidget::insertItem() instead.
602
615
\fn QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent, int type)
604
617
Constructs an empty list widget item of the specified \a type with the
605
given \a icon, \a text and \a parent.
606
If the parent is not specified, the item will need to be inserted into a
607
list widget with QListWidget::insertItem().
618
given \a icon, \a text and \a parent. If the parent is not specified, the
619
item will need to be inserted into a list widget with
620
QListWidget::insertItem().
622
This constructor inserts the item into the model of the parent that is
623
passed to the constructor. If the model is sorted then the behavior of the
624
insert is undetermined since the model will call the \c '<' operator method
625
on the item which, at this point, is not yet constructed. To avoid the
626
undetermined behavior, we recommend not to specify the parent and use
627
QListWidget::insertItem() instead.
645
This function sets the data for a given \a role to the given \a value (see
646
\l{Qt::ItemDataRole}). Reimplement this function if you need
647
extra roles or special behavior for certain roles.
665
Sets the data for a given \a role to the given \a value. Reimplement this
666
function if you need extra roles or special behavior for certain roles.
649
\sa Qt::ItemDataRole, data()
668
\sa Qt::ItemDataRole, data()
651
670
void QListWidgetItem::setData(int role, const QVariant &value)
671
This function returns the item's data for a given \a role (see
672
Qt::ItemDataRole). Reimplement this function if you need
673
extra roles or special behavior for certain roles.
690
Returns the item's data for a given \a role. Reimplement this function if
691
you need extra roles or special behavior for certain roles.
693
\sa Qt::ItemDataRole, setData()
675
695
QVariant QListWidgetItem::data(int role) const
827
\fn QFont QListWidgetItem::font() const
851
\fn QFont QListWidgetItem::font() const
829
Returns the font used to display this list item's text.
853
Returns the font used to display this list item's text.
833
\fn int QListWidgetItem::textAlignment() const
835
Returns the text alignment for the list item (see \l{Qt::AlignmentFlag}).
857
\fn int QListWidgetItem::textAlignment() const
859
Returns the text alignment for the list item.
861
\sa Qt::AlignmentFlag
881
\fn QSize QListWidgetItem::sizeHint() const
884
Returns the size hint set for the list item.
888
\fn void QListWidgetItem::setSizeHint(const QSize &size)
891
Sets the size hint for the list item to be \a size.
892
If no size hint is set, the item delegate will compute the
893
size hint based on the item data.
897
\fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
899
Sets the item flags for the list item to \a flags (see
907
\fn QSize QListWidgetItem::sizeHint() const
910
Returns the size hint set for the list item.
914
\fn void QListWidgetItem::setSizeHint(const QSize &size)
917
Sets the size hint for the list item to be \a size. If no size hint is set,
918
the item delegate will compute the size hint based on the item data.
922
\fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
924
Sets the item flags for the list item to \a flags.
902
928
void QListWidgetItem::setFlags(Qt::ItemFlags aflags) {
903
929
itemFlags = aflags;
926
952
\fn void QListWidgetItem::setStatusTip(const QString &statusTip)
928
954
Sets the status tip for the list item to the text specified by
929
\a statusTip. QListWidget mouse tracking needs to be enabled for this
955
\a statusTip. QListWidget mouseTracking needs to be enabled for this
932
\sa statusTip() setToolTip() setWhatsThis()
958
\sa statusTip(), setToolTip(), setWhatsThis(), QWidget::setMouseTracking()
938
964
Sets the tooltip for the list item to the text specified by \a toolTip.
940
\sa toolTip() setStatusTip() setWhatsThis()
966
\sa toolTip(), setStatusTip(), setWhatsThis()
944
970
\fn void QListWidgetItem::setWhatsThis(const QString &whatsThis)
946
Sets the "What's This?" help for the list item to the text specified
949
\sa whatsThis() setStatusTip() setToolTip()
953
\fn void QListWidgetItem::setFont(const QFont &font)
955
Sets the font used when painting the item to the given \a font.
959
\fn void QListWidgetItem::setTextAlignment(int alignment)
961
Sets the list item's text alignment to \a alignment (see
962
\l{Qt::AlignmentFlag}).
972
Sets the "What's This?" help for the list item to the text specified by
975
\sa whatsThis(), setStatusTip(), setToolTip()
979
\fn void QListWidgetItem::setFont(const QFont &font)
981
Sets the font used when painting the item to the given \a font.
985
\fn void QListWidgetItem::setTextAlignment(int alignment)
987
Sets the list item's text alignment to \a alignment.
989
\sa Qt::AlignmentFlag
1014
1041
QObject::connect(q, SIGNAL(activated(QModelIndex)),
1015
1042
q, SLOT(_q_emitItemActivated(QModelIndex)));
1016
1043
QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex)));
1017
QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1044
QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1018
1045
q, SLOT(_q_emitItemChanged(QModelIndex)));
1019
1046
QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
1020
1047
q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex)));
1021
1048
QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
1022
1049
q, SIGNAL(itemSelectionChanged()));
1023
QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1050
QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
1024
1051
q, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
1025
QObject::connect(model(), SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));
1052
QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort()));
1028
1055
void QListWidgetPrivate::_q_emitItemPressed(const QModelIndex &index)
1030
1057
Q_Q(QListWidget);
1031
emit q->itemPressed(model()->at(index.row()));
1058
emit q->itemPressed(listModel()->at(index.row()));
1034
1061
void QListWidgetPrivate::_q_emitItemClicked(const QModelIndex &index)
1036
1063
Q_Q(QListWidget);
1037
emit q->itemClicked(model()->at(index.row()));
1064
emit q->itemClicked(listModel()->at(index.row()));
1040
1067
void QListWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index)
1042
1069
Q_Q(QListWidget);
1043
emit q->itemDoubleClicked(model()->at(index.row()));
1070
emit q->itemDoubleClicked(listModel()->at(index.row()));
1046
1073
void QListWidgetPrivate::_q_emitItemActivated(const QModelIndex &index)
1048
1075
Q_Q(QListWidget);
1049
emit q->itemActivated(model()->at(index.row()));
1076
emit q->itemActivated(listModel()->at(index.row()));
1052
1079
void QListWidgetPrivate::_q_emitItemEntered(const QModelIndex &index)
1054
1081
Q_Q(QListWidget);
1055
emit q->itemEntered(model()->at(index.row()));
1082
emit q->itemEntered(listModel()->at(index.row()));
1058
1085
void QListWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)
1060
1087
Q_Q(QListWidget);
1061
emit q->itemChanged(model()->at(index.row()));
1088
emit q->itemChanged(listModel()->at(index.row()));
1064
1091
void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t,
1067
1094
Q_Q(QListWidget);
1068
1095
QPersistentModelIndex persistentCurrent = current;
1069
QListWidgetItem *currentItem = model()->at(persistentCurrent.row());
1070
emit q->currentItemChanged(currentItem, model()->at(previous.row()));
1096
QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row());
1097
emit q->currentItemChanged(currentItem, listModel()->at(previous.row()));
1072
1099
//persistentCurrent is invalid if something changed the model in response
1073
1100
//to the currentItemChanged signal emission and the item was removed
1082
1109
void QListWidgetPrivate::_q_sort()
1084
1111
if (sortingEnabled)
1085
model()->sort(0, sortOrder);
1112
model->sort(0, sortOrder);
1088
1115
void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
1089
1116
const QModelIndex &bottomRight)
1091
1118
if (sortingEnabled && topLeft.isValid() && bottomRight.isValid())
1092
model()->ensureSorted(topLeft.column(), sortOrder,
1119
listModel()->ensureSorted(topLeft.column(), sortOrder,
1093
1120
topLeft.row(), bottomRight.row());
1098
1125
\brief The QListWidget class provides an item-based list widget.
1100
1127
\ingroup model-view
1103
QListWidget is a convenience class that provides a list view similar to
1104
the one supplied by QListView, but with a classic item-based interface
1105
for adding and removing items. QListWidget uses an internal model to
1106
manage each QListWidgetItem in the list.
1130
QListWidget is a convenience class that provides a list view similar to the
1131
one supplied by QListView, but with a classic item-based interface for
1132
adding and removing items. QListWidget uses an internal model to manage
1133
each QListWidgetItem in the list.
1108
1135
For a more flexible list view widget, use the QListView class with a
1109
1136
standard model.
1120
1147
There are two ways to add items to the list: they can be constructed with
1121
the list widget as their parent widget, or they can be constructed with
1122
no parent widget and added to the list later. If a list widget already
1123
exists when the items are constructed, the first method is easier to use:
1148
the list widget as their parent widget, or they can be constructed with no
1149
parent widget and added to the list later. If a list widget already exists
1150
when the items are constructed, the first method is easier to use:
1125
1152
\snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 1
1127
If you need to insert a new item into the list at a particular position,
1128
it is more required to construct the item without a parent widget and
1129
use the insertItem() function to place it within the list. The list
1130
widget will take ownership of the item.
1154
If you need to insert a new item into the list at a particular position, it
1155
is more required to construct the item without a parent widget and use the
1156
insertItem() function to place it within the list. The list widget will
1157
take ownership of the item.
1132
1159
\snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 6
1133
1160
\snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 7
1135
For multiple items, insertItems() can be used instead. The number of
1136
items in the list is found with the count() function.
1137
To remove items from the list, use takeItem().
1162
For multiple items, insertItems() can be used instead. The number of items
1163
in the list is found with the count() function. To remove items from the
1164
list, use takeItem().
1139
1166
The current item in the list can be found with currentItem(), and changed
1140
1167
with setCurrentItem(). The user can also change the current item by
1213
1239
\fn void QListWidget::itemActivated(QListWidgetItem *item)
1215
This signal is emitted when the \a item is activated. The \a item
1216
is activated when the user clicks or double clicks on it,
1217
depending on the system configuration. It is also activated when
1218
the user presses the activation key (on Windows and X11 this is
1219
the \gui Return key, on Mac OS X it is \key{Ctrl+0}).
1241
This signal is emitted when the \a item is activated. The \a item is
1242
activated when the user clicks or double clicks on it, depending on the
1243
system configuration. It is also activated when the user presses the
1244
activation key (on Windows and X11 this is the \gui Return key, on Mac OS
1245
X it is \key{Ctrl+0}).
1223
1249
\fn void QListWidget::itemEntered(QListWidgetItem *item)
1225
This signal is emitted when the mouse cursor enters an item. The
1226
\a item is the item entered. This signal is only emitted when
1227
mouseTracking is turned on, or when a mouse button is pressed
1228
while moving into an item.
1251
This signal is emitted when the mouse cursor enters an item. The \a item is
1252
the item entered. This signal is only emitted when mouseTracking is turned
1253
on, or when a mouse button is pressed while moving into an item.
1255
\sa QWidget::setMouseTracking()
1238
1265
\fn void QListWidget::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
1240
This signal is emitted whenever the current item changes. The \a
1241
previous item is the item that previously had the focus, \a
1242
current is the new current item.
1246
\fn void QListWidget::currentTextChanged(const QString ¤tText)
1248
This signal is emitted whenever the current item changes. The \a currentText
1249
is the text data in the current item. If there is no current item, the \a currentText
1254
\fn void QListWidget::currentRowChanged(int currentRow)
1256
This signal is emitted whenever the current item changes. The \a currentRow
1257
is the row of the current item. If there is no current item, the \a currentRow is -1.
1267
This signal is emitted whenever the current item changes.
1269
\a previous is the item that previously had the focus; \a current is the
1274
\fn void QListWidget::currentTextChanged(const QString ¤tText)
1276
This signal is emitted whenever the current item changes.
1278
\a currentText is the text data in the current item. If there is no current
1279
item, the \a currentText is invalid.
1283
\fn void QListWidget::currentRowChanged(int currentRow)
1285
This signal is emitted whenever the current item changes.
1287
\a currentRow is the row of the current item. If there is no current item,
1288
the \a currentRow is -1.
1263
1294
This signal is emitted whenever the selection changes.
1265
\sa selectedItems() isItemSelected() currentItemChanged()
1296
\sa selectedItems(), QListWidgetItem::isSelected(), currentItemChanged()
1271
\fn void QListWidget::removeItemWidget(QListWidgetItem *item)
1273
Removes the widget set on the given \a item.
1302
\fn void QListWidget::removeItemWidget(QListWidgetItem *item)
1304
Removes the widget set on the given \a item.
1356
1387
void QListWidget::insertItems(int row, const QStringList &labels)
1358
1389
Q_D(QListWidget);
1359
d->model()->insert(row, labels);
1390
d->listModel()->insert(row, labels);
1363
Removes and returns the item from the given \a row in the list widget; otherwise
1394
Removes and returns the item from the given \a row in the list widget;
1395
otherwise returns 0.
1366
Items removed from a list widget will not be managed by Qt, and will need to be
1397
Items removed from a list widget will not be managed by Qt, and will need
1398
to be deleted manually.
1369
1400
\sa insertItem(), addItem()
1372
1403
QListWidgetItem *QListWidget::takeItem(int row)
1374
1405
Q_D(QListWidget);
1375
if (row < 0 || row >= d->model()->rowCount())
1406
if (row < 0 || row >= d->model->rowCount())
1377
return d->model()->take(row);
1408
return d->listModel()->take(row);
1381
\property QListWidget::count
1382
\brief the number of items in the list including any hidden items.
1412
\property QListWidget::count
1413
\brief the number of items in the list including any hidden items.
1385
1416
int QListWidget::count() const
1387
1418
Q_D(const QListWidget);
1388
return d->model()->rowCount();
1419
return d->model->rowCount();
1392
Returns the current item.
1423
Returns the current item.
1394
1425
QListWidgetItem *QListWidget::currentItem() const
1396
1427
Q_D(const QListWidget);
1397
return d->model()->at(currentIndex().row());
1428
return d->listModel()->at(currentIndex().row());
1402
Sets the current item to \a item.
1433
Sets the current item to \a item.
1404
Depending on the current selection mode, the item may also be selected.
1435
Unless the selection mode is \l{QAbstractItemView::}{NoSelection},
1436
the item is also be selected.
1406
1438
void QListWidget::setCurrentItem(QListWidgetItem *item)
1421
\property QListWidget::currentRow
1422
\brief the row of the current item.
1453
\property QListWidget::currentRow
1454
\brief the row of the current item.
1424
Depending on the current selection mode, the row may also be selected.
1456
Depending on the current selection mode, the row may also be selected.
1427
1459
int QListWidget::currentRow() const
1447
Sets the current row to be the given \a row, using the given \a command,
1479
Sets the current row to be the given \a row, using the given \a command,
1449
1481
void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
1451
1483
Q_D(QListWidget);
1452
d->selectionModel->setCurrentIndex(d->model()->index(row), command);
1484
d->selectionModel->setCurrentIndex(d->listModel()->index(row), command);
1474
Returns the rectangle on the viewport occupied by the item at \a item.
1506
Returns the rectangle on the viewport occupied by the item at \a item.
1476
1508
QRect QListWidget::visualItemRect(const QListWidgetItem *item) const
1478
1510
Q_D(const QListWidget);
1479
QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
1511
QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1480
1512
return visualRect(index);
1484
Sorts all the items in the list widget according to the specified \a order.
1516
Sorts all the items in the list widget according to the specified \a order.
1486
1518
void QListWidget::sortItems(Qt::SortOrder order)
1488
1520
Q_D(QListWidget);
1489
1521
d->sortOrder = order;
1490
d->model()->sort(0, order);
1522
d->listModel()->sort(0, order);
1495
1527
\property QListWidget::sortingEnabled
1496
1528
\brief whether sorting is enabled
1498
If this property is true, sorting is enabled for the list; if the
1499
property is false, sorting is not enabled. The default value is false.
1530
If this property is true, sorting is enabled for the list; if the property
1531
is false, sorting is not enabled.
1533
The default value is false.
1501
1535
void QListWidget::setSortingEnabled(bool enable)
1523
Starts editing the \a item if it is editable.
1557
Starts editing the \a item if it is editable.
1526
1560
void QListWidget::editItem(QListWidgetItem *item)
1528
1562
Q_D(QListWidget);
1529
edit(d->model()->index(item));
1563
edit(d->listModel()->index(item));
1533
Opens an editor for the given \a item. The editor remains open after editing.
1567
Opens an editor for the given \a item. The editor remains open after
1535
\sa closePersistentEditor()
1570
\sa closePersistentEditor()
1537
1572
void QListWidget::openPersistentEditor(QListWidgetItem *item)
1539
1574
Q_D(QListWidget);
1540
QModelIndex index = d->model()->index(item);
1575
QModelIndex index = d->listModel()->index(item);
1541
1576
QAbstractItemView::openPersistentEditor(index);
1545
Closes the persistent editor for the given \a item.
1580
Closes the persistent editor for the given \a item.
1547
\sa openPersistentEditor()
1582
\sa openPersistentEditor()
1549
1584
void QListWidget::closePersistentEditor(QListWidgetItem *item)
1551
1586
Q_D(QListWidget);
1552
QModelIndex index = d->model()->index(item);
1587
QModelIndex index = d->listModel()->index(item);
1553
1588
QAbstractItemView::closePersistentEditor(index);
1571
1606
Sets the \a widget to be displayed in the give \a item.
1573
This function should only be used to display static content in the place of a list
1574
widget item. If you want to display custom dynamic content or implement a custom
1575
editor widget, use QListView and subclass QItemDelegate instead.
1608
This function should only be used to display static content in the place of
1609
a list widget item. If you want to display custom dynamic content or
1610
implement a custom editor widget, use QListView and subclass QItemDelegate
1577
1613
\sa {Delegate Classes}
1579
1615
void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
1581
1617
Q_D(QListWidget);
1582
QModelIndex index = d->model()->index(item);
1618
QModelIndex index = d->listModel()->index(item);
1583
1619
QAbstractItemView::setIndexWidget(index, widget);
1587
Returns true if \a item is selected; otherwise returns false.
1591
This function is deprecated. Use \l{QListWidgetItem::isSelected()} instead.
1623
Returns true if \a item is selected; otherwise returns false.
1627
This function is deprecated. Use QListWidgetItem::isSelected() instead.
1593
1629
bool QListWidget::isItemSelected(const QListWidgetItem *item) const
1595
1631
Q_D(const QListWidget);
1596
QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
1632
QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1597
1633
return selectionModel()->isSelected(index);
1601
Selects or deselects the given \a item depending on whether \a select is
1606
This function is deprecated. Use \l{QListWidgetItem::setSelected()} instead.
1637
Selects or deselects the given \a item depending on whether \a select is
1642
This function is deprecated. Use QListWidgetItem::setSelected() instead.
1608
1644
void QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
1610
1646
Q_D(QListWidget);
1611
QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
1647
QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1613
1649
if (d->selectionMode == SingleSelection) {
1614
1650
selectionModel()->select(index, select
1632
1668
QModelIndexList indexes = selectionModel()->selectedIndexes();
1633
1669
QList<QListWidgetItem*> items;
1634
1670
for (int i = 0; i < indexes.count(); ++i)
1635
items.append(d->model()->at(indexes.at(i).row()));
1671
items.append(d->listModel()->at(indexes.at(i).row()));
1640
Finds items with the text that matches the string \a text using the given \a flags.
1676
Finds items with the text that matches the string \a text using the given
1643
1680
QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const
1645
1682
Q_D(const QListWidget);
1646
QModelIndexList indexes = d->model()->match(model()->index(0, 0, QModelIndex()),
1683
QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()),
1647
1684
Qt::DisplayRole, text, -1, flags);
1648
1685
QList<QListWidgetItem*> items;
1649
1686
for (int i = 0; i < indexes.size(); ++i)
1650
items.append(d->model()->at(indexes.at(i).row()));
1687
items.append(d->listModel()->at(indexes.at(i).row()));
1655
Returns true if the \a item is explicitly hidden; otherwise returns false.
1659
This function is deprecated. Use \l{QListWidgetItem::isHidden()} instead.
1692
Returns true if the \a item is explicitly hidden; otherwise returns false.
1696
This function is deprecated. Use QListWidgetItem::isHidden() instead.
1661
1698
bool QListWidget::isItemHidden(const QListWidgetItem *item) const
1679
Scrolls the view if necessary to ensure that the \a item is
1680
visible. The \a hint parameter specifies more precisely where the
1681
\a item should be located after the operation.
1716
Scrolls the view if necessary to ensure that the \a item is visible.
1718
\a hint specifies where the \a item should be located after the operation.
1684
1721
void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint)
1686
1723
Q_D(QListWidget);
1687
QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));
1724
QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
1688
1725
QListView::scrollTo(index, hint);
1692
1729
Removes all items and selections in the view.
1694
\note All items will be permanently deleted.
1731
\warning All items will be permanently deleted.
1696
1733
void QListWidget::clear()
1698
1735
Q_D(QListWidget);
1699
1736
selectionModel()->clear();
1700
d->model()->clear();
1737
d->listModel()->clear();
1716
1753
\a items. The format used to describe the items is obtained from the
1717
1754
mimeTypes() function.
1719
If the list of items is empty, 0 is returned rather than a serialized
1756
If the list of items is empty, 0 is returned instead of a serialized empty
1722
1759
QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*>) const
1724
return d_func()->model()->internalMimeData();
1761
return d_func()->listModel()->internalMimeData();
1727
1764
#ifndef QT_NO_DRAGANDDROP
1729
Handles the \a data supplied by an external drag and drop operation
1730
that ended with the given \a action in the given \a index.
1731
Returns true if the data and action can be handled by the model;
1732
otherwise returns false.
1766
Handles \a data supplied by an external drag and drop operation that ended
1767
with the given \a action in the given \a index. Returns true if \a data and
1768
\a action can be handled by the model; otherwise returns false.
1734
1770
\sa supportedDropActions()
1799
Returns the drop actions supported by this view.
1835
Returns the drop actions supported by this view.
1803
1839
Qt::DropActions QListWidget::supportedDropActions() const
1805
1841
Q_D(const QListWidget);
1806
return d->model()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
1842
return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;
1808
1844
#endif // QT_NO_DRAGANDDROP
1811
Returns a list of pointers to the items contained in the \a data object.
1812
If the object was not created by a QListWidget in the same process, the list
1847
Returns a list of pointers to the items contained in the \a data object. If
1848
the object was not created by a QListWidget in the same process, the list
1815
1851
QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const
1824
Returns the QModelIndex assocated with the given \a item.
1860
Returns the QModelIndex assocated with the given \a item.
1827
1863
QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const
1829
1865
Q_D(const QListWidget);
1830
return d->model()->index(item);
1866
return d->listModel()->index(item);
1834
Returns a pointer to the QListWidgetItem assocated with the given \a index.
1870
Returns a pointer to the QListWidgetItem assocated with the given \a index.
1837
1873
QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const
1839
1875
Q_D(const QListWidget);
1840
1876
if (d->isIndexValid(index))
1841
return d->model()->at(index.row());
1877
return d->listModel()->at(index.row());
1848
1884
void QListWidget::setModel(QAbstractItemModel * /*model*/)