QtBase
v6.3.1
|
The QListWidget class provides an item-based list widget. More...
#include <qlistwidget.h>
Public Slots | |
void | scrollToItem (const QListWidgetItem *item, QAbstractItemView::ScrollHint hint=EnsureVisible) |
void | clear () |
Public Slots inherited from QAbstractItemView | |
virtual void | selectAll () |
void | edit (const QModelIndex &index) |
void | clearSelection () |
void | setCurrentIndex (const QModelIndex &index) |
void | scrollToTop () |
void | scrollToBottom () |
void | update (const QModelIndex &index) |
Signals | |
void | itemPressed (QListWidgetItem *item) |
void | itemClicked (QListWidgetItem *item) |
void | itemDoubleClicked (QListWidgetItem *item) |
void | itemActivated (QListWidgetItem *item) |
void | itemEntered (QListWidgetItem *item) |
void | itemChanged (QListWidgetItem *item) |
void | currentItemChanged (QListWidgetItem *current, QListWidgetItem *previous) |
void | currentTextChanged (const QString ¤tText) |
void | currentRowChanged (int currentRow) |
void | itemSelectionChanged () |
Signals inherited from QListView | |
void | indexesMoved (const QModelIndexList &indexes) |
Signals inherited from QAbstractItemView | |
void | pressed (const QModelIndex &index) |
void | clicked (const QModelIndex &index) |
void | doubleClicked (const QModelIndex &index) |
void | activated (const QModelIndex &index) |
void | entered (const QModelIndex &index) |
void | viewportEntered () |
void | iconSizeChanged (const QSize &size) |
Properties | |
int | count |
the number of items in the list including any hidden items. More... | |
int | currentRow |
the row of the current item. More... | |
bool | sortingEnabled |
whether sorting is enabled More... | |
Properties inherited from QListView | |
Movement | movement |
whether the items can be moved freely, are snapped to a grid, or cannot be moved at all. More... | |
Flow | flow |
which direction the items layout should flow. More... | |
bool | isWrapping |
whether the items layout should wrap. More... | |
ResizeMode | resizeMode |
whether the items are laid out again when the view is resized. More... | |
LayoutMode | layoutMode |
determines whether the layout of items should happen immediately or be delayed. More... | |
int | spacing |
the space around the items in the layout More... | |
QSize | gridSize |
the size of the layout grid More... | |
ViewMode | viewMode |
the view mode of the QListView. More... | |
int | modelColumn |
the column in the model that is visible More... | |
bool | uniformItemSizes |
whether all items in the listview have the same size More... | |
int | batchSize |
the number of items laid out in each batch if \l layoutMode is set to \l Batched More... | |
bool | wordWrap |
the item text word-wrapping policy More... | |
bool | selectionRectVisible |
if the selection rectangle should be visible More... | |
Qt::Alignment | itemAlignment |
the alignment of each item in its cell More... | |
Properties inherited from QAbstractItemView | |
bool | autoScroll |
whether autoscrolling in drag move events is enabled More... | |
int | autoScrollMargin |
the size of the area when auto scrolling is triggered More... | |
EditTriggers | editTriggers |
which actions will initiate item editing More... | |
bool | tabKeyNavigation |
whether item navigation with tab and backtab is enabled. More... | |
bool | alternatingRowColors |
whether to draw the background using alternating colors More... | |
SelectionMode | selectionMode |
which selection mode the view operates in More... | |
SelectionBehavior | selectionBehavior |
which selection behavior the view uses More... | |
QSize | iconSize |
the size of items' icons More... | |
Qt::TextElideMode | textElideMode |
the position of the "..." in elided text. More... | |
ScrollMode | verticalScrollMode |
how the view scrolls its contents in the vertical direction More... | |
ScrollMode | horizontalScrollMode |
how the view scrolls its contents in the horizontal direction More... | |
Friends | |
class | QListWidgetItem |
class | QListModel |
The QListWidget class provides an item-based list widget.
\inmodule QtWidgets
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:
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:
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.
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.
Definition at line 187 of file qlistwidget.h.
Constructs an empty QListWidget with the given parent.
Definition at line 1405 of file qlistwidget.cpp.
QListWidget::~QListWidget | ( | ) |
Destroys the list widget and all its items.
Definition at line 1416 of file qlistwidget.cpp.
Inserts an item with the text label at the end of the list widget.
Definition at line 208 of file qlistwidget.h.
|
inline |
Inserts the item at the end of the list widget.
Definition at line 300 of file qlistwidget.h.
|
inline |
Inserts items with the text labels at the end of the list widget.
Definition at line 210 of file qlistwidget.h.
|
slot |
Removes all items and selections in the view.
Definition at line 1814 of file qlistwidget.cpp.
void QListWidget::closePersistentEditor | ( | QListWidgetItem * | item | ) |
Closes the persistent editor for the given item.
Definition at line 1708 of file qlistwidget.cpp.
int QListWidget::count | ( | ) | const |
Definition at line 1535 of file qlistwidget.cpp.
QListWidgetItem * QListWidget::currentItem | ( | ) | const |
Returns the current item.
Definition at line 1544 of file qlistwidget.cpp.
|
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.
int QListWidget::currentRow | ( | ) | const |
|
signal |
This signal is emitted whenever the current item changes.
currentRow is the row of the current item. If there is no current item, the currentRow is -1.
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::editItem | ( | QListWidgetItem * | item | ) |
Starts editing the item if it is editable.
Definition at line 1684 of file qlistwidget.cpp.
|
overrideprotected |
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.
Definition at line 1783 of file qlistwidget.cpp.
QModelIndex QListWidget::indexFromItem | ( | const QListWidgetItem * | item | ) | const |
Returns the QModelIndex associated with the given item.
{const} item. Definition at line 1920 of file qlistwidget.cpp.
Inserts an item with the text label in the list widget at the position given by row.
Definition at line 1493 of file qlistwidget.cpp.
void QListWidget::insertItem | ( | int | row, |
QListWidgetItem * | item | ||
) |
Inserts the item at the position in the list given by row.
Definition at line 1479 of file qlistwidget.cpp.
void QListWidget::insertItems | ( | int | row, |
const QStringList & | labels | ||
) |
Inserts items from the list of labels into the list, starting at the given row.
Definition at line 1506 of file qlistwidget.cpp.
bool QAbstractItemView::isPersistentEditorOpen |
Returns whether a persistent editor is open for the item at index index.
Definition at line 218 of file qabstractitemview.cpp.
bool QListWidget::isPersistentEditorOpen | ( | QListWidgetItem * | item | ) | const |
Returns whether a persistent editor is open for item item.
Definition at line 1722 of file qlistwidget.cpp.
bool QListWidget::isSortingEnabled | ( | ) | const |
QListWidgetItem * QListWidget::item | ( | int | row | ) | const |
Returns the item that occupies the given row in the list if one has been set; otherwise returns \nullptr.
Definition at line 1452 of file qlistwidget.cpp.
|
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 \uicontrol Return key, on Mac OS X it is \uicontrol{Command+O}).
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 \l{QAbstractScrollArea::}{viewport()}.
Definition at line 1611 of file qlistwidget.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a pointer to the item at the coordinates (x, y). The coordinates are relative to the list widget's \l{QAbstractScrollArea::}{viewport()}.
Definition at line 303 of file qlistwidget.h.
|
signal |
This signal is emitted whenever the data of item has changed.
|
signal |
This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.
|
signal |
This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.
|
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.
QListWidgetItem * QListWidget::itemFromIndex | ( | const QModelIndex & | index | ) | const |
Returns a pointer to the QListWidgetItem associated with the given index.
Definition at line 1930 of file qlistwidget.cpp.
|
signal |
This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.
QList< QListWidgetItem * > QListWidget::items | ( | const QMimeData * | data | ) | const |
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.
Definition at line 1906 of file qlistwidget.cpp.
|
signal |
This signal is emitted whenever the selection changes.
QWidget * QListWidget::itemWidget | ( | QListWidgetItem * | item | ) | const |
Returns the widget displayed in the given item.
Definition at line 1736 of file qlistwidget.cpp.
|
protectedvirtual |
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, \nullptr is returned instead of a serialized empty list.
Definition at line 1840 of file qlistwidget.cpp.
|
protectedvirtual |
Returns a list of MIME types that can be used to describe a list of listwidget items.
Definition at line 1827 of file qlistwidget.cpp.
void QListWidget::openPersistentEditor | ( | QListWidgetItem * | item | ) |
Opens an editor for the given item. The editor remains open after editing.
Definition at line 1696 of file qlistwidget.cpp.
|
inline |
Removes the widget set on the given item.
To remove an item (row) from the list entirely, either delete the item or use takeItem().
Definition at line 297 of file qlistwidget.h.
int QListWidget::row | ( | const QListWidgetItem * | item | ) | const |
Returns the row containing the given item.
Definition at line 1466 of file qlistwidget.cpp.
|
slot |
Scrolls the view if necessary to ensure that the item is visible.
hint specifies where the item should be located after the operation.
Definition at line 1802 of file qlistwidget.cpp.
QList< QListWidgetItem * > QListWidget::selectedItems | ( | ) | const |
Returns a list of all selected items in the list widget.
Definition at line 1766 of file qlistwidget.cpp.
void QListWidget::setCurrentItem | ( | QListWidgetItem * | item | ) |
Sets the current item to item.
Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, the item is also selected.
Definition at line 1557 of file qlistwidget.cpp.
void QListWidget::setCurrentItem | ( | QListWidgetItem * | item, |
QItemSelectionModel::SelectionFlags | command | ||
) |
Definition at line 1566 of file qlistwidget.cpp.
void QListWidget::setCurrentRow | ( | int | row | ) |
Definition at line 1583 of file qlistwidget.cpp.
void QListWidget::setCurrentRow | ( | int | row, |
QItemSelectionModel::SelectionFlags | command | ||
) |
Sets the current row to be the given row, using the given command,
Definition at line 1600 of file qlistwidget.cpp.
void QListWidget::setItemWidget | ( | QListWidgetItem * | item, |
QWidget * | widget | ||
) |
Sets the widget to be displayed in the given 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 QStyledItemDelegate instead.
Definition at line 1755 of file qlistwidget.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemView.
Definition at line 1424 of file qlistwidget.cpp.
void QListWidget::setSortingEnabled | ( | bool | enable | ) |
void QListWidget::sortItems | ( | Qt::SortOrder | order = Qt::AscendingOrder | ) |
Sorts all the items in the list widget according to the specified order.
Definition at line 1642 of file qlistwidget.cpp.
QListWidgetItem * QListWidget::takeItem | ( | int | row | ) |
Removes and returns the item from the given row in the list widget; otherwise returns \nullptr.
Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.
Definition at line 1522 of file qlistwidget.cpp.
QRect QListWidget::visualItemRect | ( | const QListWidgetItem * | item | ) | const |
Returns the rectangle on the viewport occupied by the item at item.
Definition at line 1632 of file qlistwidget.cpp.
|
friend |
Definition at line 196 of file qlistwidget.h.
|
friend |
Definition at line 195 of file qlistwidget.h.
|
read |
the number of items in the list including any hidden items.
Definition at line 155 of file qlistwidget.h.
|
readwrite |
the row of the current item.
Depending on the current selection mode, the row may also be selected.
Definition at line 155 of file qlistwidget.h.
|
readwrite |
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.
Definition at line 155 of file qlistwidget.h.