Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QListWidget Class

TheQListWidget class provides an item-based list widget.More...

Header:#include <QListWidget>
Inherits:QListView

Properties

Public Functions

QListWidget(QWidget * parent = 0)
~QListWidget()
voidaddItem(const QString & label)
voidaddItem(QListWidgetItem * item)
voidaddItems(const QStringList & labels)
voidclosePersistentEditor(QListWidgetItem * item)
intcount() const
QListWidgetItem *currentItem() const
intcurrentRow() const
voideditItem(QListWidgetItem * item)
QList<QListWidgetItem *>findItems(const QString & text, Qt::MatchFlags flags) const
voidinsertItem(int row, QListWidgetItem * item)
voidinsertItem(int row, const QString & label)
voidinsertItems(int row, const QStringList & labels)
boolisSortingEnabled() const
QListWidgetItem *item(int row) const
QListWidgetItem *itemAt(const QPoint & p) const
QListWidgetItem *itemAt(int x, int y) const
QWidget *itemWidget(QListWidgetItem * item) const
voidopenPersistentEditor(QListWidgetItem * item)
voidremoveItemWidget(QListWidgetItem * item)
introw(const QListWidgetItem * item) const
QList<QListWidgetItem *>selectedItems() const
voidsetCurrentItem(QListWidgetItem * item)
voidsetCurrentItem(QListWidgetItem * item, QItemSelectionModel::SelectionFlags command)
voidsetCurrentRow(int row)
voidsetCurrentRow(int row, QItemSelectionModel::SelectionFlags command)
voidsetItemWidget(QListWidgetItem * item, QWidget * widget)
voidsetSortingEnabled(bool enable)
voidsortItems(Qt::SortOrder order = Qt::AscendingOrder)
QListWidgetItem *takeItem(int row)
QRectvisualItemRect(const QListWidgetItem * item) const

Reimplemented Public Functions

virtual voiddropEvent(QDropEvent * event)

Public Slots

voidclear()
voidscrollToItem(const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible)

Signals

voidcurrentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
voidcurrentRowChanged(int currentRow)
voidcurrentTextChanged(const QString & currentText)
voiditemActivated(QListWidgetItem * item)
voiditemChanged(QListWidgetItem * item)
voiditemClicked(QListWidgetItem * item)
voiditemDoubleClicked(QListWidgetItem * item)
voiditemEntered(QListWidgetItem * item)
voiditemPressed(QListWidgetItem * item)
voiditemSelectionChanged()

Protected Functions

virtual booldropMimeData(int index, const QMimeData * data, Qt::DropAction action)
QModelIndexindexFromItem(QListWidgetItem * item) const
QListWidgetItem *itemFromIndex(const QModelIndex & index) const
QList<QListWidgetItem *>items(const QMimeData * data) const
virtual QMimeData *mimeData(const QList<QListWidgetItem *> items) const
virtual QStringListmimeTypes() const
virtual Qt::DropActionssupportedDropActions() const

Reimplemented Protected Functions

virtual boolevent(QEvent * e)

Additional Inherited Members

Detailed Description

TheQListWidget class provides an item-based list widget.

QListWidget is a convenience class that provides a list view similar to the one supplied byQListView, but with a classic item-based interface for adding and removing items.QListWidget uses an internal model to manage eachQListWidgetItem in the list.

For a more flexible list view widget, use theQListView class with a standard model.

List widgets are constructed in the same way as other widgets:

    QListWidget *listWidget = new QListWidget(this);

TheselectionMode() 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 thesetSelectionMode() 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:

newQListWidgetItem(tr("Oak"), listWidget);newQListWidgetItem(tr("Fir"), listWidget);newQListWidgetItem(tr("Pine"), listWidget);

If you need to insert a new item into the list at a particular position, then it should be constructed without a parent widget. TheinsertItem() function should then be used to place it within the list. The list widget will take ownership of the item.

QListWidgetItem*newItem=newQListWidgetItem;    newItem->setText(itemText);    listWidget->insertItem(row, newItem);

For multiple items,insertItems() can be used instead. The number of items in the list is found with thecount() function. To remove items from the list, usetakeItem().

The current item in the list can be found withcurrentItem(), and changed withsetCurrentItem(). The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, thecurrentItemChanged() signal is emitted with the new current item and the item that was previously current.

Screenshot of a Windows XP style list widgetScreenshot of a Macintosh style table widgetScreenshot of a Plastique style table widget
AWindows XP style list widget.AMacintosh style list widget.APlastique style list widget.

See alsoQListWidgetItem,QListView,QTreeView,Model/View Programming, andConfig Dialog Example.

Property Documentation

count : constint

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

Access functions:

intcount() const

currentRow :int

This property holds the row of the current item.

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

Access functions:

intcurrentRow() const
voidsetCurrentRow(int row)
voidsetCurrentRow(int row, QItemSelectionModel::SelectionFlags command)

Notifier signal:

voidcurrentRowChanged(int currentRow)

sortingEnabled :bool

This property holds whether sorting is enabled.

If this property is true, sorting is enabled for the list; if the property is false, sorting is not enabled.

The default value is false.

This property was introduced in Qt 4.2.

Access functions:

boolisSortingEnabled() const
voidsetSortingEnabled(bool enable)

Member Function Documentation

QListWidget::QListWidget(QWidget * parent = 0)

Constructs an emptyQListWidget with the givenparent.

QListWidget::~QListWidget()

Destroys the list widget and all its items.

void QListWidget::addItem(constQString & label)

Inserts an item with the textlabel at the end of the list widget.

void QListWidget::addItem(QListWidgetItem * item)

Inserts theitem at the end of the list widget.

Warning: AQListWidgetItem can only be added to aQListWidget once. Adding the sameQListWidgetItem multiple times to aQListWidget will result in undefined behavior.

See alsoinsertItem().

void QListWidget::addItems(constQStringList & labels)

Inserts items with the textlabels at the end of the list widget.

See alsoinsertItems().

[slot]void QListWidget::clear()

Removes all items and selections in the view.

Warning: All items will be permanently deleted.

void QListWidget::closePersistentEditor(QListWidgetItem * item)

Closes the persistent editor for the givenitem.

See alsoopenPersistentEditor().

QListWidgetItem * QListWidget::currentItem() const

Returns the current item.

See alsosetCurrentItem().

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

This signal is emitted whenever the current item changes.

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

[signal]void QListWidget::currentTextChanged(constQString & currentText)

This signal is emitted whenever the current item changes.

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

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

Reimplemented fromQWidget::dropEvent().

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

Handlesdata supplied by an external drag and drop operation that ended with the givenaction in the givenindex. Returns true ifdata andaction can be handled by the model; otherwise returns false.

See alsosupportedDropActions().

void QListWidget::editItem(QListWidgetItem * item)

Starts editing theitem if it is editable.

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

Reimplemented fromQObject::event().

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

Finds items with the text that matches the stringtext using the givenflags.

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

Returns theQModelIndex assocated with the givenitem.

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

Inserts theitem at the position in the list given byrow.

See alsoaddItem().

void QListWidget::insertItem(int row, constQString & label)

Inserts an item with the textlabel in the list widget at the position given byrow.

See alsoaddItem().

void QListWidget::insertItems(int row, constQStringList & labels)

Inserts items from the list oflabels into the list, starting at the givenrow.

See alsoinsertItem() andaddItem().

QListWidgetItem * QListWidget::item(int row) const

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

See alsorow().

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

This signal is emitted when theitem is activated. Theitem 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 theReturn key, on Mac OS X it isCtrl+0).

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

Returns a pointer to the item at the coordinatesp. The coordinates are relative to the list widget'sviewport().

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

This is an overloaded function.

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

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

This signal is emitted whenever the data ofitem has changed.

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

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

See alsoitemPressed() anditemDoubleClicked().

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

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

See alsoitemClicked() anditemPressed().

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

This signal is emitted when the mouse cursor enters an item. Theitem is the item entered. This signal is only emitted whenmouseTracking is turned on, or when a mouse button is pressed while moving into an item.

See alsoQWidget::setMouseTracking().

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

Returns a pointer to theQListWidgetItem assocated with the givenindex.

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

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

See alsoitemClicked() anditemDoubleClicked().

[signal]void QListWidget::itemSelectionChanged()

This signal is emitted whenever the selection changes.

See alsoselectedItems(),QListWidgetItem::isSelected(), andcurrentItemChanged().

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

Returns the widget displayed in the givenitem.

This function was introduced in Qt 4.1.

See alsosetItemWidget().

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

Returns a list of pointers to the items contained in thedata object. If the object was not created by aQListWidget in the same process, the list is empty.

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

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

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

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

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

See alsomimeData().

void QListWidget::openPersistentEditor(QListWidgetItem * item)

Opens an editor for the givenitem. The editor remains open after editing.

See alsoclosePersistentEditor().

void QListWidget::removeItemWidget(QListWidgetItem * item)

Removes the widget set on the givenitem.

This function was introduced in Qt 4.3.

int QListWidget::row(constQListWidgetItem * item) const

Returns the row containing the givenitem.

See alsoitem().

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

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

hint specifies where theitem should be located after the operation.

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

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

void QListWidget::setCurrentItem(QListWidgetItem * item)

Sets the current item toitem.

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

See alsocurrentItem().

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

Set the current item toitem, using the givencommand.

This function was introduced in Qt 4.4.

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

Sets thewidget to be displayed in the giveitem.

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, useQListView and subclassQItemDelegate instead.

This function was introduced in Qt 4.1.

See alsoitemWidget() andDelegate Classes.

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

Sorts all the items in the list widget according to the specifiedorder.

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

Returns the drop actions supported by this view.

See alsoQt::DropActions.

QListWidgetItem * QListWidget::takeItem(int row)

Removes and returns the item from the givenrow in the list widget; otherwise returns 0.

Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

See alsoinsertItem() andaddItem().

QRect QListWidget::visualItemRect(constQListWidgetItem * item) const

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

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp