|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.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. |
QListWidgetItem
, QListView
, QTreeView
, Model/View Programming, and Config Dialog Example.
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, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal2 |
currentItemChanged
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
currentRowChanged
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
currentTextChanged
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemActivated
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemChanged
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemClicked
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemDoubleClicked
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemEntered
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
itemPressed
This signal takes 1 generic argument(s). |
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 |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QListWidget()
Constructs an empty QListWidget with the given parent. |
|
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 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()
This property holds the number of items in the list including any hidden items. |
QListWidgetItem |
currentItem()
Returns the current item. |
int |
currentRow()
This property holds the row of the current item. |
protected boolean |
dropMimeData(int index,
QMimeData data,
Qt.DropAction action)
Handles the data supplied by an external 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. |
java.util.List |
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 |
findItems(java.lang.String text,
Qt.MatchFlags flags)
Finds items with the text that matches the string text using the given flags. |
protected com.trolltech.qt.core.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)
This is an overloaded member function, provided for convenience. |
void |
insertItems(int row,
java.util.List labels)
Inserts items from the list of labels into the list, starting at the given row. |
boolean |
isSortingEnabled()
This property holds 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(com.trolltech.qt.core.QModelIndex index)
Returns a pointer to the QListWidgetItem assocated with the given index. |
protected java.util.List |
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 items)
Returns an object that contains a serialized description of the specified items. |
protected java.util.List |
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)
Scrolls the view if necessary to ensure that the item is visible. |
void |
scrollToItem(QListWidgetItem item,
QAbstractItemView.ScrollHint hint)
Scrolls the view if necessary to ensure that the item is visible. |
java.util.List |
selectedItems()
Returns a list of all selected items in the list widget. |
void |
setCurrentItem(QListWidgetItem item)
Sets the current item to item. |
void |
setCurrentItem(QListWidgetItem item,
QItemSelectionModel.SelectionFlag[] command)
Set the current item to item, using the given command. |
void |
setCurrentItem(QListWidgetItem item,
QItemSelectionModel.SelectionFlags command)
Set the current item to item, using the given command. |
void |
setCurrentRow(int row)
This property holds the row of the current item. |
void |
setCurrentRow(int row,
QItemSelectionModel.SelectionFlag[] command)
This property holds the row of the current item. |
void |
setCurrentRow(int row,
QItemSelectionModel.SelectionFlags command)
This property holds the row of the current item. |
void |
setItemWidget(QListWidgetItem item,
QWidget widget)
Sets the widget to be displayed in the give item. |
void |
setSortingEnabled(boolean enable)
This property holds whether sorting is enabled. |
void |
sortItems()
Sorts all the items in the list widget according to the specified order. |
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.QListView |
---|
batchSize, clearPropertyFlags, flow, gridSize, isRowHidden, isSelectionRectVisible, isWrapping, layoutMode, modelColumn, movement, rectForIndex, resizeMode, setBatchSize, setFlow, setGridSize, setLayoutMode, setModelColumn, setMovement, setPositionForIndex, setResizeMode, setRowHidden, setSelectionRectVisible, setSpacing, setUniformItemSizes, setViewMode, setWordWrap, setWrapping, spacing, uniformItemSizes, viewMode, wordWrap |
Methods inherited from class com.trolltech.qt.gui.QFrame |
---|
frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal2 currentItemChanged
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: current), com.trolltech.qt.gui.QListWidgetItem(named: previous)>:
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 currentRowChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: currentRow)>:
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 currentTextChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: currentText)>:
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 itemActivated
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
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 itemChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
This signal is emitted whenever the data of item has changed.
public final QSignalEmitter.Signal1 itemClicked
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.
itemPressed()
, and itemDoubleClicked()
.
public final QSignalEmitter.Signal1 itemDoubleClicked
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.
itemClicked()
, and itemPressed()
.
public final QSignalEmitter.Signal1 itemEntered
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
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 itemPressed
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QListWidgetItem(named: item)>:
This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.
itemClicked()
, and itemDoubleClicked()
.
public final QSignalEmitter.Signal0 itemSelectionChanged
selectedItems()
, isItemSelected(), and currentItemChanged()
.
Constructor Detail |
---|
public QListWidget()
QListWidget
with the given parent.
public QListWidget(QWidget parent)
QListWidget
with the given parent.
Method Detail |
---|
public final void addItem(QListWidgetItem item)
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.
insertItem()
.
public final void clear()
Note: All items will be permanently deleted.
public final void closePersistentEditor(QListWidgetItem item)
openPersistentEditor()
.
public final int count()
public final QListWidgetItem currentItem()
setCurrentItem()
.
public final int currentRow()
public final void editItem(QListWidgetItem item)
public final java.util.List findItems(java.lang.String text, Qt.MatchFlag[] flags)
public final java.util.List findItems(java.lang.String text, Qt.MatchFlags flags)
protected final com.trolltech.qt.core.QModelIndex indexFromItem(QListWidgetItem item)
public final void insertItem(int row, QListWidgetItem item)
addItem()
.
public final boolean isSortingEnabled()
public final QListWidgetItem item(int row)
row()
.
public final QListWidgetItem itemAt(QPoint p)
public final QListWidgetItem itemAt(int x, int y)
protected final QListWidgetItem itemFromIndex(com.trolltech.qt.core.QModelIndex index)
QListWidgetItem
assocated with the given index.
public final QWidget itemWidget(QListWidgetItem item)
setItemWidget()
.
protected final java.util.List items(QMimeData data)
QListWidget
in the same process, the list is empty.
public final void openPersistentEditor(QListWidgetItem item)
closePersistentEditor()
.
public final void removeItemWidget(QListWidgetItem item)
public final int row(QListWidgetItem item)
item()
.
public final void scrollToItem(QListWidgetItem item)
public final void scrollToItem(QListWidgetItem item, QAbstractItemView.ScrollHint hint)
public final java.util.List selectedItems()
public final void setCurrentItem(QListWidgetItem item)
Depending on the current selection mode, the item may also be selected.
currentItem()
.
public final void setCurrentItem(QListWidgetItem item, QItemSelectionModel.SelectionFlag[] command)
public final void setCurrentItem(QListWidgetItem item, QItemSelectionModel.SelectionFlags command)
public final void setCurrentRow(int row)
public final void setCurrentRow(int row, QItemSelectionModel.SelectionFlag[] command)
public final void setCurrentRow(int row, QItemSelectionModel.SelectionFlags command)
public final void setItemWidget(QListWidgetItem item, QWidget widget)
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.
itemWidget()
, and Delegate Classes.
public final void setSortingEnabled(boolean enable)
public final void sortItems()
public final void sortItems(Qt.SortOrder order)
public final QListWidgetItem takeItem(int row)
Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.
insertItem()
, and addItem()
.
public final QRect visualItemRect(QListWidgetItem item)
protected boolean dropMimeData(int index, QMimeData data, Qt.DropAction action)
supportedDropActions()
.
protected QMimeData mimeData(java.util.List items)
mimeTypes()
function. If the list of items is empty, 0 is returned rather than a serialized empty list.
protected java.util.List mimeTypes()
mimeData()
.
protected Qt.DropActions supportedDropActions()
public final void addItem(java.lang.String label)
label
- The text of the new item.public final void addItems(java.util.List labels)
labels
- The collection of labels for the new items.public final void insertItem(int row, java.lang.String label)
row
- The position in which to insert the new item.label
- The text of the new item.public final void insertItems(int row, java.util.List labels)
row
- The position in which to insert the new items.labels
- The collection of labels for the new items.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |