|
|||||||||
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.QTreeView
com.trolltech.qt.gui.QTreeWidget
public class QTreeWidget
The QTreeWidget class provides a tree view that uses a predefined tree model. The QTreeWidget class is a convenience class that provides a standard tree widget with a classic item-based interface similar to that used by the QListView
class in Qt 3. This class is based on Qt's Model/View architecture and uses a default model to hold items, each of which is a QTreeWidgetItem
.
Developers who do not need the flexibility of the Model/View framework can use this class to create simple hierarchical lists very easily. A more flexible approach involves combining a QTreeView
with a standard item model. This allows the storage of data to be separated from its representation.
In its simplest form, a tree widget can be constructed in the following way:
QTreeWidget treeWidget = new QTreeWidget(); treeWidget.setColumnCount(1); List<QTreeWidgetItem> items = new ArrayList<QTreeWidgetItem>(); for (int i = 0; i < 10; ++i) { List<String> lst = new ArrayList<String>(); lst.add("item: " + i); items.add(new QTreeWidgetItem((QTreeWidgetItem) null, lst)); } treeWidget.insertTopLevelItems(0, items);Before items can be added to the tree widget, the number of columns must be set with
setColumnCount()
. This allows each item to have one or more labels or other decorations. The number of columns in use can be found with the columnCount()
function. The tree can have a header that contains a section for each column in the widget. It is easiest to set up the labels for each section by supplying a list of strings with setHeaderLabels()
, but a custom header can be constructed with a QTreeWidgetItem
and inserted into the tree with the setHeaderItem()
function.
The items in the tree can be sorted by column according to a predefined sort order. If sorting is enabled, the user can sort the items by clicking on a column header. Sorting can be enabled or disabled by calling setSortingEnabled()
. The isSortingEnabled()
function indicates whether sorting is enabled.
![]() | ![]() | ![]() |
A Windows XP style tree widget. | A Macintosh style tree widget. | A Plastique style tree widget. |
QTreeWidgetItem
, QTreeWidgetItemIterator
, QTreeView
, Model/View Programming, and Settings Editor Example.
Nested Class Summary |
---|
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.Signal2 |
itemActivated
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
itemChanged
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
itemClicked
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
itemCollapsed
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal2 |
itemDoubleClicked
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
itemEntered
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal1 |
itemExpanded
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal2 |
itemPressed
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal0 |
itemSelectionChanged
This signal is emitted when the selection changes in the tree widget. |
Fields inherited from class com.trolltech.qt.gui.QTreeView |
---|
collapsed, expanded |
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 | |
---|---|
QTreeWidget()
Constructs a tree widget with the given parent. |
|
QTreeWidget(QWidget parent)
Constructs a tree widget with the given parent. |
Method Summary | |
---|---|
void |
addTopLevelItem(QTreeWidgetItem item)
Appends the item as a top-level item in the widget. |
void |
addTopLevelItems(java.util.List items)
Appends the list of items as a top-level items in the widget. |
void |
clear()
Clears the tree widget by removing all of its items and selections. |
void |
closePersistentEditor(QTreeWidgetItem item)
Closes the persistent editor for the item in the given column. |
void |
closePersistentEditor(QTreeWidgetItem item,
int column)
Closes the persistent editor for the item in the given column. |
void |
collapseItem(QTreeWidgetItem item)
Closes the item. |
int |
columnCount()
This property holds the number of columns displayed in the tree widget. |
int |
currentColumn()
Returns the current column in the tree widget. |
QTreeWidgetItem |
currentItem()
Returns the current item in the tree widget. |
protected boolean |
dropMimeData(QTreeWidgetItem parent,
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 index in the given parent item. |
void |
editItem(QTreeWidgetItem item)
Starts editing the item in the given column if it is editable. |
void |
editItem(QTreeWidgetItem item,
int column)
Starts editing the item in the given column if it is editable. |
void |
expandItem(QTreeWidgetItem item)
Expands the item. |
java.util.List |
findItems(java.lang.String text,
Qt.MatchFlags flags)
Returns a list of items that match the given text, using the given flags, in the given column. |
java.util.List |
findItems(java.lang.String text,
Qt.MatchFlags flags,
int column)
Returns a list of items that match the given text, using the given flags, in the given column. |
QTreeWidgetItem |
headerItem()
Returns the item used for the tree widget's header. |
protected com.trolltech.qt.core.QModelIndex |
indexFromItem(QTreeWidgetItem item)
Returns the QModelIndex assocated with the given item in the given column. |
protected com.trolltech.qt.core.QModelIndex |
indexFromItem(QTreeWidgetItem item,
int column)
Returns the QModelIndex assocated with the given item in the given column. |
void |
insertTopLevelItem(int index,
QTreeWidgetItem item)
Inserts the item at index in the top level in the view. |
void |
insertTopLevelItems(int index,
java.util.List items)
Inserts the list of items at index in the top level in the view. |
QTreeWidgetItem |
invisibleRootItem()
Returns the tree widget's invisible root item. |
boolean |
isFirstItemColumnSpanned(QTreeWidgetItem item)
Returns true if the given item is set to show only one section over all columns; otherwise returns false. |
QTreeWidgetItem |
itemAbove(QTreeWidgetItem item)
Returns the item above the given item. |
QTreeWidgetItem |
itemAt(int x,
int y)
Returns a pointer to the item at the coordinates (x, y). |
QTreeWidgetItem |
itemAt(QPoint p)
Returns a pointer to the item at the coordinates p. |
QTreeWidgetItem |
itemBelow(QTreeWidgetItem item)
Returns the item visually below the given item. |
protected QTreeWidgetItem |
itemFromIndex(com.trolltech.qt.core.QModelIndex index)
Returns a pointer to the QTreeWidgetItem assocated with the given index. |
QWidget |
itemWidget(QTreeWidgetItem item,
int column)
Returns the widget displayed in the cell specified by item and the given column. |
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 treewidget items. |
void |
openPersistentEditor(QTreeWidgetItem item)
Opens a persistent editor for the item in the given column. |
void |
openPersistentEditor(QTreeWidgetItem item,
int column)
Opens a persistent editor for the item in the given column. |
void |
removeItemWidget(QTreeWidgetItem item,
int column)
Removes the widget set in the given item in the given column. |
void |
scrollToItem(QTreeWidgetItem item)
Ensures that the item is visible, scrolling the view if necessary using the specified hint. |
void |
scrollToItem(QTreeWidgetItem item,
QAbstractItemView.ScrollHint hint)
Ensures that the item is visible, scrolling the view if necessary using the specified hint. |
java.util.List |
selectedItems()
Returns a list of all selected non-hidden items. |
void |
setColumnCount(int columns)
This property holds the number of columns displayed in the tree widget. |
void |
setCurrentItem(QTreeWidgetItem item)
Sets the current item in the tree widget. |
void |
setCurrentItem(QTreeWidgetItem item,
int column)
Sets the current item in the tree widget and the current column to column. |
void |
setCurrentItem(QTreeWidgetItem item,
int column,
QItemSelectionModel.SelectionFlag[] command)
|
void |
setCurrentItem(QTreeWidgetItem item,
int column,
QItemSelectionModel.SelectionFlags command)
Sets the current item in the tree widget and the current column to column, using the given command. |
void |
setFirstItemColumnSpanned(QTreeWidgetItem item,
boolean span)
Sets the given item to only show one section for all columns if span is true; otherwise the item will show one section per column. |
void |
setHeaderItem(QTreeWidgetItem item)
Sets the header item for the tree widget. |
void |
setHeaderLabel(java.lang.String label)
Same as setHeaderLabels(QStringList(label)). |
void |
setHeaderLabels(java.util.List labels)
Adds a column in the header for each item in the labels list, and sets the label for each column. |
void |
setItemWidget(QTreeWidgetItem item,
int column,
QWidget widget)
Sets the given widget to be displayed in the cell specified by the given item and column. |
int |
sortColumn()
Returns the column used to sort the contents of the widget. |
void |
sortItems(int column,
Qt.SortOrder order)
Sorts the items in the widget in the specified order by the values in the given column. |
protected Qt.DropActions |
supportedDropActions()
Returns the drop actions supported by this view. |
QTreeWidgetItem |
takeTopLevelItem(int index)
Removes the top-level item at the given index in the tree and returns it, otherwise returns 0; |
QTreeWidgetItem |
topLevelItem(int index)
Returns the top level item at the given index, or 0 if the item does not exist. |
int |
topLevelItemCount()
This property holds the number of top-level items. |
QRect |
visualItemRect(QTreeWidgetItem item)
Returns the rectangle on the viewport occupied by the item at item. |
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.QTreeWidgetItem(named: current), com.trolltech.qt.gui.QTreeWidgetItem(named: previous)>:
This signal is emitted when the current item changes. The current item is specified by current, and this replaces the previous current item.
setCurrentItem()
.
public final QSignalEmitter.Signal2 itemActivated
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the user activates an item by single- or double-clicking (depending on the platform, i. . on the QStyle::SH_ItemView_ActivateItemOnSingleClick
style hint) or pressing a special key (e.g., Enter).
The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.
public final QSignalEmitter.Signal2 itemChanged
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the contents of the column in the specified item changes.
public final QSignalEmitter.Signal2 itemClicked
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the user clicks inside the widget.
The specified item is the item that was clicked. The column is the item's column that was clicked. If no item was clicked, no signal will be emitted.
public final QSignalEmitter.Signal1 itemCollapsed
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.QTreeWidgetItem(named: item)>:
This signal is emitted when the specified item is collapsed so that none of its children are displayed.
Note: This signal will not be emitted if an item changes its state when collapseAll()
is invoked.
itemExpanded()
, and collapseItem()
.
public final QSignalEmitter.Signal2 itemDoubleClicked
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the user double clicks inside the widget.
The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked. If no item was double clicked, no signal will be emitted.
public final QSignalEmitter.Signal2 itemEntered
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the mouse cursor enters an item over the specified column. QTreeWidget mouse tracking needs to be enabled for this feature to work.
public final QSignalEmitter.Signal1 itemExpanded
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.QTreeWidgetItem(named: item)>:
This signal is emitted when the specified item is expanded so that all of its children are displayed.
Note: This signal will not be emitted if an item changes its state when expandAll()
is invoked.
itemCollapsed()
, and expandItem()
.
public final QSignalEmitter.Signal2 itemPressed
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.QTreeWidgetItem(named: item), java.lang.Integer(named: column)>:
This signal is emitted when the user presses a mouse button inside the widget.
The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.
public final QSignalEmitter.Signal0 itemSelectionChanged
selectedItems()
.
Constructor Detail |
---|
public QTreeWidget()
public QTreeWidget(QWidget parent)
Method Detail |
---|
public final void addTopLevelItem(QTreeWidgetItem item)
insertTopLevelItem()
.
public final void addTopLevelItems(java.util.List items)
insertTopLevelItems()
.
public final void clear()
Note: Since each item is removed from the tree widget before being deleted, the return value of QTreeWidgetItem::treeWidget()
will be invalid when called from an item's destructor.
takeTopLevelItem()
, topLevelItemCount()
, and columnCount()
.
public final void closePersistentEditor(QTreeWidgetItem item)
This function has no effect if no persistent editor is open for this combination of item and column.
openPersistentEditor()
.
public final void closePersistentEditor(QTreeWidgetItem item, int column)
This function has no effect if no persistent editor is open for this combination of item and column.
openPersistentEditor()
.
public final void collapseItem(QTreeWidgetItem item)
expandItem()
, currentItem()
, itemAt()
, and topLevelItem()
.
public final int columnCount()
public final int currentColumn()
setCurrentItem()
, and columnCount()
.
public final QTreeWidgetItem currentItem()
setCurrentItem()
, and currentItemChanged()
.
public final void editItem(QTreeWidgetItem item)
public final void editItem(QTreeWidgetItem item, int column)
public final void expandItem(QTreeWidgetItem item)
collapseItem()
, currentItem()
, itemAt()
, topLevelItem()
, and itemExpanded()
.
public final java.util.List findItems(java.lang.String text, Qt.MatchFlags flags)
public final java.util.List findItems(java.lang.String text, Qt.MatchFlags flags, int column)
public final QTreeWidgetItem headerItem()
setHeaderItem()
.
protected final com.trolltech.qt.core.QModelIndex indexFromItem(QTreeWidgetItem item)
itemFromIndex()
, and topLevelItem()
.
protected final com.trolltech.qt.core.QModelIndex indexFromItem(QTreeWidgetItem item, int column)
itemFromIndex()
, and topLevelItem()
.
public final void insertTopLevelItem(int index, QTreeWidgetItem item)
If the item has already been inserted somewhere else it wont be inserted.
addTopLevelItem()
, and columnCount()
.
public final void insertTopLevelItems(int index, java.util.List items)
Items that have already been inserted somewhere else wont be inserted.
addTopLevelItems()
.
public final QTreeWidgetItem invisibleRootItem()
The invisible root item provides access to the tree widget's top-level items through the QTreeWidgetItem
API, making it possible to write functions that can treat top-level items and their children in a uniform way; for example, recursive functions.
public final boolean isFirstItemColumnSpanned(QTreeWidgetItem item)
setFirstItemColumnSpanned()
.
public final QTreeWidgetItem itemAbove(QTreeWidgetItem item)
public final QTreeWidgetItem itemAt(QPoint p)
visualItemRect()
.
public final QTreeWidgetItem itemAt(int x, int y)
public final QTreeWidgetItem itemBelow(QTreeWidgetItem item)
protected final QTreeWidgetItem itemFromIndex(com.trolltech.qt.core.QModelIndex index)
QTreeWidgetItem
assocated with the given index. indexFromItem()
.
public final QWidget itemWidget(QTreeWidgetItem item, int column)
Note: The tree takes ownership of the widget.
setItemWidget()
.
public final void openPersistentEditor(QTreeWidgetItem item)
closePersistentEditor()
.
public final void openPersistentEditor(QTreeWidgetItem item, int column)
closePersistentEditor()
.
public final void removeItemWidget(QTreeWidgetItem item, int column)
public final void scrollToItem(QTreeWidgetItem item)
currentItem()
, itemAt()
, and topLevelItem()
.
public final void scrollToItem(QTreeWidgetItem item, QAbstractItemView.ScrollHint hint)
currentItem()
, itemAt()
, and topLevelItem()
.
public final java.util.List selectedItems()
itemSelectionChanged()
.
public final void setColumnCount(int columns)
public final void setCurrentItem(QTreeWidgetItem item)
Depending on the current selection mode, the item may also be selected.
currentItem()
, and currentItemChanged()
.
public final void setCurrentItem(QTreeWidgetItem item, int column)
currentItem()
.
public final void setCurrentItem(QTreeWidgetItem item, int column, QItemSelectionModel.SelectionFlag[] command)
public final void setCurrentItem(QTreeWidgetItem item, int column, QItemSelectionModel.SelectionFlags command)
currentItem()
.
public final void setFirstItemColumnSpanned(QTreeWidgetItem item, boolean span)
isFirstItemColumnSpanned()
.
public final void setHeaderItem(QTreeWidgetItem item)
The tree widget takes ownership of the item.
headerItem()
, and setHeaderLabels()
.
public final void setHeaderLabel(java.lang.String label)
public final void setHeaderLabels(java.util.List labels)
Note that setHeaderLabels()
won't remove existing columns.
setHeaderItem()
, and setHeaderLabel()
.
public final void setItemWidget(QTreeWidgetItem item, int column, QWidget widget)
Note that the given widget's autoFillBackground
property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.
This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView
and subclass QItemDelegate
instead.
Note: The tree takes ownership of the widget.
itemWidget()
, and Delegate Classes.
public final int sortColumn()
sortItems()
.
public final void sortItems(int column, Qt.SortOrder order)
sortColumn()
.
public final QTreeWidgetItem takeTopLevelItem(int index)
insertTopLevelItem()
, topLevelItem()
, and topLevelItemCount()
.
public final QTreeWidgetItem topLevelItem(int index)
topLevelItemCount()
, and insertTopLevelItem()
.
public final int topLevelItemCount()
columnCount()
, and currentItem()
.
public final QRect visualItemRect(QTreeWidgetItem item)
itemAt()
.
protected boolean dropMimeData(QTreeWidgetItem parent, int index, QMimeData data, Qt.DropAction action)
The default implementation returns true if the drop was successfully handled by decoding the mime data and inserting it into the model; otherwise it returns false.
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()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |