|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QFrame
com.trolltech.qt.gui.QAbstractScrollArea
com.trolltech.qt.gui.QAbstractItemView
com.trolltech.qt.gui.QListView
com.trolltech.qt.gui.QListWidget
public class QListWidget
The QListWidget class provides an item-based list widget.
QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list.
For a more flexible list view widget, use the QListView class with a standard model.
List widgets are constructed in the same way as other widgets:
QListWidget *listWidget = new QListWidget(this);
The selectionMode of a list widget determines how many of the items in the list can be selected at the same time, and whether complex selections of items can be created. This can be set with the setSelectionMode function.
There are two ways to add items to the list: they can be constructed with the list widget as their parent widget, or they can be constructed with no parent widget and added to the list later. If a list widget already exists when the items are constructed, the first method is easier to use:
new QListWidgetItem(tr("Oak"), listWidget); new QListWidgetItem(tr("Fir"), listWidget); new QListWidgetItem(tr("Pine"), listWidget);
If you need to insert a new item into the list at a particular position, it is more required to construct the item without a parent widget and use the insertItem function to place it within the list. The list widget will take ownership of the item.
QListWidgetItem *newItem = new QListWidgetItem; newItem->setText(itemText); listWidget->insertItem(row, newItem);
For multiple items, insertItems can be used instead. The number of items in the list is found with the count function. To remove items from the list, use takeItem.
The current item in the list can be found with currentItem, and changed with setCurrentItem. The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, the currentItemChanged signal is emitted with the new current item and the item that was previously current.
![]() | ![]() | ![]() |
A Windows XP style list widget. | A Macintosh style list widget. | A Plastique style list widget. |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QListView |
---|
QListView.Flow, QListView.LayoutMode, QListView.Movement, QListView.ResizeMode, QListView.ViewMode |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QAbstractItemView |
---|
QAbstractItemView.CursorAction, QAbstractItemView.DragDropMode, QAbstractItemView.DropIndicatorPosition, QAbstractItemView.EditTrigger, QAbstractItemView.EditTriggers, QAbstractItemView.ScrollHint, QAbstractItemView.ScrollMode, QAbstractItemView.SelectionBehavior, QAbstractItemView.SelectionMode, QAbstractItemView.State |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QFrame |
---|
QFrame.Shadow, QFrame.Shape, QFrame.StyleMask |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary | |
---|---|
QSignalEmitter.Signal2<QListWidgetItem,QListWidgetItem> |
currentItemChanged
This signal is emitted whenever the current item changes. |
QSignalEmitter.Signal1<java.lang.Integer> |
currentRowChanged
This signal is emitted whenever the current item changes. |
QSignalEmitter.Signal1<java.lang.String> |
currentTextChanged
This signal is emitted whenever the current item changes. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemActivated
This signal is emitted when the item is activated. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemChanged
This signal is emitted whenever the data of item has changed. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemClicked
This signal is emitted with the specified item when a mouse button is clicked on an item in the widget. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemDoubleClicked
This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemEntered
This signal is emitted when the mouse cursor enters an item. |
QSignalEmitter.Signal1<QListWidgetItem> |
itemPressed
This signal is emitted with the specified item when a mouse button is pressed on an item in the widget. |
QSignalEmitter.Signal0 |
itemSelectionChanged
This signal is emitted whenever the selection changes. |
Fields inherited from class com.trolltech.qt.gui.QListView |
---|
indexesMoved |
Fields inherited from class com.trolltech.qt.gui.QAbstractItemView |
---|
activated, clicked, doubleClicked, entered, pressed, viewportEntered |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QListWidget()
Equivalent to QListWidget(0). |
|
QListWidget(QWidget parent)
Constructs an empty QListWidget with the given parent. |
Method Summary | |
---|---|
void |
addItem(QListWidgetItem item)
Inserts the item at the the end of the list widget. |
void |
addItem(java.lang.String label)
Inserts an item with the text label at the end of the list widget. |
void |
addItems(java.util.List<java.lang.String> labels)
Inserts items with the text labels at the end of the list widget. |
void |
clear()
Removes all items and selections in the view. |
void |
closePersistentEditor(QListWidgetItem item)
Closes the persistent editor for the given item. |
int |
count()
Returns the number of items in the list including any hidden items.. |
QListWidgetItem |
currentItem()
Returns the current item. |
int |
currentRow()
Returns the row of the current item.. |
protected void |
dropEvent(QDropEvent event)
This function is reimplemented for internal reasons. |
protected boolean |
dropMimeData(int index,
QMimeData data,
Qt.DropAction action)
Handles the data supplied by a drag and drop operation that ended with the given action in the given index. |
void |
editItem(QListWidgetItem item)
Starts editing the item if it is editable. |
boolean |
event(QEvent e)
This function is reimplemented for internal reasons. |
java.util.List<QListWidgetItem> |
findItems(java.lang.String text,
Qt.MatchFlag... flags)
Finds items with the text that matches the string text using the given flags. |
java.util.List<QListWidgetItem> |
findItems(java.lang.String text,
Qt.MatchFlags flags)
Finds items with the text that matches the string text using the given flags. |
static QListWidget |
fromNativePointer(QNativePointer nativePointer)
This function returns the QListWidget instance pointed to by nativePointer |
protected QModelIndex |
indexFromItem(QListWidgetItem item)
Returns the QModelIndex assocated with the given item. |
void |
insertItem(int row,
QListWidgetItem item)
Inserts the item at the position in the list given by row. |
void |
insertItem(int row,
java.lang.String label)
Inserts an item with the text label in the list widget at the position given by row. |
void |
insertItems(int row,
java.util.List<java.lang.String> labels)
Inserts items from the list of labels into the list, starting at the given row. |
boolean |
isSortingEnabled()
Returns whether sorting is enabled. |
QListWidgetItem |
item(int row)
Returns the item that occupies the given row in the list if one has been set; otherwise returns 0. |
QListWidgetItem |
itemAt(int x,
int y)
Returns a pointer to the item at the coordinates (x, y). |
QListWidgetItem |
itemAt(QPoint p)
Returns a pointer to the item at the coordinates p. |
protected QListWidgetItem |
itemFromIndex(QModelIndex index)
Returns a pointer to the QListWidgetItem assocated with the given index. |
protected java.util.List<QListWidgetItem> |
items(QMimeData data)
Returns a list of pointers to the items contained in the data object. |
QWidget |
itemWidget(QListWidgetItem item)
Returns the widget displayed in the given item. |
protected QMimeData |
mimeData(java.util.List<QListWidgetItem> items)
Returns an object that contains a serialized description of the specified items. |
protected java.util.List<java.lang.String> |
mimeTypes()
Returns a list of MIME types that can be used to describe a list of listwidget items. |
void |
openPersistentEditor(QListWidgetItem item)
Opens an editor for the given item. |
void |
removeItemWidget(QListWidgetItem item)
Removes the widget set on the given item. |
int |
row(QListWidgetItem item)
Returns the row containing the given item. |
void |
scrollToItem(QListWidgetItem item)
Equivalent to scrollToItem(item, EnsureVisible). |
void |
scrollToItem(QListWidgetItem item,
QAbstractItemView.ScrollHint hint)
Scrolls the view if necessary to ensure that the item is visible. |
java.util.List<QListWidgetItem> |
selectedItems()
Returns a list of all selected items in the list widget. |
void |
setCurrentItem(QListWidgetItem item)
Sets the current item to item. |
void |
setCurrentRow(int row)
Sets the row of the current item. to row. |
void |
setItemWidget(QListWidgetItem item,
QWidget widget)
Sets the widget to be displayed in the give item. |
void |
setModel(QAbstractItemModel model)
Deprecated. |
void |
setSortingEnabled(boolean enable)
Sets whether sorting is enabled to enable. |
void |
sortItems()
Equivalent to sortItems(Qt::AscendingOrder). |
void |
sortItems(Qt.SortOrder order)
Sorts all the items in the list widget according to the specified order. |
protected Qt.DropActions |
supportedDropActions()
Returns the drop actions supported by this view. |
QListWidgetItem |
takeItem(int row)
Removes and returns the item from the given row in the list widget; otherwise returns 0. |
QRect |
visualItemRect(QListWidgetItem item)
Returns the rectangle on the viewport occupied by the item at item. |
Methods inherited from class com.trolltech.qt.gui.QFrame |
---|
changeEvent, drawFrame, frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal2<QListWidgetItem,QListWidgetItem> currentItemChanged
This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.
public final QSignalEmitter.Signal1<java.lang.Integer> currentRowChanged
This signal is emitted whenever the current item changes. The currentRow is the row of the current item. If there is no current item, the currentRow is -1.
public final QSignalEmitter.Signal1<java.lang.String> currentTextChanged
This signal is emitted whenever the current item changes. The currentText is the text data in the current item. If there is no current item, the currentText is invalid.
public final QSignalEmitter.Signal1<QListWidgetItem> itemActivated
This signal is emitted when the item is activated. The item is activated when the user clicks or double clicks on it, depending on the system configuration. It is also activated when the user presses the activation key (on Windows and X11 this is the Return key, on Mac OS X it is Ctrl+0).
public final QSignalEmitter.Signal1<QListWidgetItem> itemChanged
This signal is emitted whenever the data of item has changed.
public final QSignalEmitter.Signal1<QListWidgetItem> itemClicked
This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.
public final QSignalEmitter.Signal1<QListWidgetItem> itemDoubleClicked
This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.
public final QSignalEmitter.Signal1<QListWidgetItem> itemEntered
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.
public final QSignalEmitter.Signal1<QListWidgetItem> itemPressed
This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.
public final QSignalEmitter.Signal0 itemSelectionChanged
This signal is emitted whenever the selection changes.
Constructor Detail |
---|
public QListWidget()
Equivalent to QListWidget(0).
public QListWidget(QWidget parent)
Constructs an empty QListWidget with the given parent.
Method Detail |
---|
public final void addItem(java.lang.String label)
Inserts an item with the text label at the end of the list widget.
public final void addItem(QListWidgetItem item)
Inserts the item at the the end of the list widget.
Warning: A QListWidgetItem can only be added to a QListWidget once. Adding the same QListWidgetItem multiple times to a QListWidget will result in undefined behavior.
public final void addItems(java.util.List<java.lang.String> labels)
Inserts items with the text labels at the end of the list widget.
public final void clear()
Removes all items and selections in the view.
public final void closePersistentEditor(QListWidgetItem item)
Closes the persistent editor for the given item.
public final int count()
Returns the number of items in the list including any hidden items..
public final QListWidgetItem currentItem()
Returns the current item.
public final int currentRow()
Returns the row of the current item..
Depending on the current selection mode, the row may also be selected.
public final void editItem(QListWidgetItem item)
Starts editing the item if it is editable.
public final java.util.List<QListWidgetItem> findItems(java.lang.String text, Qt.MatchFlag... flags)
Finds items with the text that matches the string text using the given flags.
public final java.util.List<QListWidgetItem> findItems(java.lang.String text, Qt.MatchFlags flags)
Finds items with the text that matches the string text using the given flags.
protected final QModelIndex indexFromItem(QListWidgetItem item)
Returns the QModelIndex assocated with the given item.
public final void insertItem(int row, java.lang.String label)
Inserts an item with the text label in the list widget at the position given by row.
public final void insertItem(int row, QListWidgetItem item)
Inserts the item at the position in the list given by row.
public final void insertItems(int row, java.util.List<java.lang.String> labels)
Inserts items from the list of labels into the list, starting at the given row.
public final boolean isSortingEnabled()
Returns 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.
public final QListWidgetItem item(int row)
Returns the item that occupies the given row in the list if one has been set; otherwise returns 0.
public final QListWidgetItem itemAt(int x, int y)
Returns a pointer to the item at the coordinates (x, y).
public final QListWidgetItem itemAt(QPoint p)
Returns a pointer to the item at the coordinates p.
protected final QListWidgetItem itemFromIndex(QModelIndex index)
Returns a pointer to the QListWidgetItem assocated with the given index.
public final QWidget itemWidget(QListWidgetItem item)
Returns the widget displayed in the given item.
protected final java.util.List<QListWidgetItem> items(QMimeData data)
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.
public final void openPersistentEditor(QListWidgetItem item)
Opens an editor for the given item. The editor remains open after editing.
public final void removeItemWidget(QListWidgetItem item)
Removes the widget set on the given item.
public final int row(QListWidgetItem item)
Returns the row containing the given item.
public final void scrollToItem(QListWidgetItem item)
Equivalent to scrollToItem(item, EnsureVisible).
public final void scrollToItem(QListWidgetItem item, QAbstractItemView.ScrollHint hint)
Scrolls the view if necessary to ensure that the item is visible. The hint parameter specifies more precisely where the item should be located after the operation.
public final java.util.List<QListWidgetItem> selectedItems()
Returns a list of all selected items in the list widget.
public final void setCurrentItem(QListWidgetItem item)
Sets the current item to item.
Depending on the current selection mode, the item may also be selected.
public final void setCurrentRow(int row)
Sets the row of the current item. to row.
Depending on the current selection mode, the row may also be selected.
public final void setItemWidget(QListWidgetItem item, QWidget widget)
Sets the widget to be displayed in the give item.
This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.
@Deprecated public final void setModel(QAbstractItemModel model)
Sets the model for the view to present.
Note: This function will also create and set a new selection model, replacing any previously set with setSelectionModel, but the old selection model will not be deleted.
setModel
in class QAbstractItemView
public final void setSortingEnabled(boolean enable)
Sets whether sorting is enabled to enable.
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.
public final void sortItems()
Equivalent to sortItems(Qt::AscendingOrder).
public final void sortItems(Qt.SortOrder order)
Sorts all the items in the list widget according to the specified order.
public final QListWidgetItem takeItem(int row)
Removes and returns the item from the given row in the list widget; otherwise returns 0.
Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.
public final QRect visualItemRect(QListWidgetItem item)
Returns the rectangle on the viewport occupied by the item at item.
protected void dropEvent(QDropEvent event)
This function is reimplemented for internal reasons.
dropEvent
in class QListView
protected boolean dropMimeData(int index, QMimeData data, Qt.DropAction action)
Handles the data supplied by a drag and drop operation that ended with the given action in the given index. Returns true if the data and action can be handled by the model; otherwise returns false.
public boolean event(QEvent e)
This function is reimplemented for internal reasons.
event
in class QListView
protected QMimeData mimeData(java.util.List<QListWidgetItem> items)
Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes function.
If the list of items is empty, 0 is returned rather than a serialized empty list.
protected java.util.List<java.lang.String> mimeTypes()
Returns a list of MIME types that can be used to describe a list of listwidget items.
protected Qt.DropActions supportedDropActions()
Returns the drop actions supported by this view.
public static QListWidget fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |