|
|||||||||
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.QTableView
com.trolltech.qt.gui.QTableWidget
public class QTableWidget
The QTableWidget class provides an item-based table view with a default model. Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem
.
If you want a table that uses your own data model you should use QTableView
rather than this class.
Table widgets can be constructed with the required numbers of rows and columns:
tableWidget = new QTableWidget(12, 3, this);Alternatively, tables can be constructed without a given size and resized later:
tableWidget = new QTableWidget(this); tableWidget.setRowCount(10); tableWidget.setColumnCount(5);Items are created ouside the table (with no parent widget) and inserted into the table with
setItem()
: QTableWidgetItem newItem = new QTableWidgetItem("" + (row+1) + ", " + (column+1)); tableWidget.setItem(row, column, newItem);If you want to enable sorting in your table widget, do so after you have populated it with items, otherwise sorting may interfere with the insertion order (see
setItem()
for details). Tables can be given both horizontal and vertical headers. The simplest way to create the headers is to supply a list of strings to the setHorizontalHeaderLabels()
and setVerticalHeaderLabels()
functions. These will provide simple textual headers for the table's columns and rows. More sophisticated headers can be created from existing table items that are usually constructed outside the table. For example, we can construct a table item with an icon and aligned text, and use it as the header for a particular column:
QTableWidgetItem cubesHeaderItem = new QTableWidgetItem(tr("Cubes")); cubesHeaderItem.setIcon(new QIcon(new QPixmap("classpath:images/cubed.png"))); cubesHeaderItem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter.value());The number of rows in the table can be found with
rowCount()
, and the number of columns with columnCount()
. The table can be cleared with the clear()
function. ![]() | ![]() | ![]() |
A Windows XP style table widget. | A Macintosh style table widget. | A Plastique style table widget. |
QTableWidgetItem
, QTableView
, and Model/View Programming.
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 |
cellActivated
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
cellChanged
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
cellClicked
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
cellDoubleClicked
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
cellEntered
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal2 |
cellPressed
This signal takes 2 generic argument(s). |
QSignalEmitter.Signal4 |
currentCellChanged
This signal takes 4 generic argument(s). |
QSignalEmitter.Signal2 |
currentItemChanged
This signal takes 2 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.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 | |
---|---|
QTableWidget()
Creates a new table view with the given parent. |
|
QTableWidget(int rows,
int columns)
Creates a new table view with the given rows and columns, and with the given parent. |
|
QTableWidget(int rows,
int columns,
QWidget parent)
Creates a new table view with the given rows and columns, and with the given parent. |
|
QTableWidget(QWidget parent)
Creates a new table view with the given parent. |
Method Summary | |
---|---|
QWidget |
cellWidget(int row,
int column)
Returns the widget displayed in the cell in the given row and column. |
void |
clear()
Removes all items in the view. |
void |
clearContents()
Removes all items not in the headers from the view. |
void |
closePersistentEditor(QTableWidgetItem item)
Closes the persistent editor for item. |
int |
column(QTableWidgetItem item)
Returns the column for the item. |
int |
columnCount()
This property holds the number of columns in the table. |
int |
currentColumn()
Returns the column of the current item. |
QTableWidgetItem |
currentItem()
Returns the current item. |
int |
currentRow()
Returns the row of the current item. |
protected boolean |
dropMimeData(int row,
int column,
QMimeData data,
Qt.DropAction action)
Handles the data supplied by a drag and drop operation that ended with the given action in the given row and column. |
void |
editItem(QTableWidgetItem item)
Starts editing the item if it is editable. |
java.util.List |
findItems(java.lang.String text,
Qt.MatchFlag[] flags)
|
java.util.List |
findItems(java.lang.String text,
Qt.MatchFlags flags)
Finds items that matches the text using the given flags. |
QTableWidgetItem |
horizontalHeaderItem(int column)
Returns the horizontal header item for column, column, if one has been set; otherwise returns 0. |
protected com.trolltech.qt.core.QModelIndex |
indexFromItem(QTableWidgetItem item)
Returns the QModelIndex assocated with the given item. |
void |
insertColumn(int column)
Inserts an empty column into the table at column. |
void |
insertRow(int row)
Inserts an empty row into the table at row. |
QTableWidgetItem |
item(int row,
int column)
Returns the item for the given row and column if one has been set; otherwise returns 0. |
QTableWidgetItem |
itemAt(int x,
int y)
Returns the item at the position equivalent to QPoint (ax, ay) in the table widget's coordinate system, or returns 0 if the specified point is not covered by an item in the table widget. |
QTableWidgetItem |
itemAt(QPoint p)
Returns a pointer to the item at the given point, or returns 0 if the point is not covered by an item in the table widget. |
protected QTableWidgetItem |
itemFromIndex(com.trolltech.qt.core.QModelIndex index)
Returns a pointer to the QTableWidgetItem assocated with the given index. |
QTableWidgetItem |
itemPrototype()
Returns the item prototype used by the table. |
protected java.util.List |
items(QMimeData data)
Returns a list of pointers to the items contained in the data object. |
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 tablewidget items. |
void |
openPersistentEditor(QTableWidgetItem item)
Opens an editor for the give item. |
void |
removeCellWidget(int row,
int column)
Removes the widget set on the cell indicated by row and column. |
void |
removeColumn(int column)
Removes the column column and all its items from the table. |
void |
removeRow(int row)
Removes the row row and all its items from the table. |
int |
row(QTableWidgetItem item)
Returns the row for the item. |
int |
rowCount()
This property holds the number of rows in the table. |
void |
scrollToItem(QTableWidgetItem item)
Scrolls the view if necessary to ensure that the item is visible. |
void |
scrollToItem(QTableWidgetItem 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. |
java.util.List |
selectedRanges()
Returns a list of all selected ranges. |
void |
setCellWidget(int row,
int column,
QWidget widget)
Sets the widget to be displayed in the cell in the given row and column. |
void |
setColumnCount(int columns)
This property holds the number of columns in the table. |
void |
setCurrentCell(int row,
int column)
Sets the current cell to be the cell at position (row, column). |
void |
setCurrentCell(int row,
int column,
QItemSelectionModel.SelectionFlag[] command)
|
void |
setCurrentCell(int row,
int column,
QItemSelectionModel.SelectionFlags command)
Sets the current cell to be the cell at position (row, column), using the given command. |
void |
setCurrentItem(QTableWidgetItem item)
Sets the current item to item. |
void |
setCurrentItem(QTableWidgetItem item,
QItemSelectionModel.SelectionFlag[] command)
|
void |
setCurrentItem(QTableWidgetItem item,
QItemSelectionModel.SelectionFlags command)
Sets the current item to be item, using the given command. |
void |
setHorizontalHeaderItem(int column,
QTableWidgetItem item)
Sets the horizontal header item for column column to item. |
void |
setHorizontalHeaderLabels(java.util.List labels)
Sets the horizontal header labels using labels. |
void |
setItem(int row,
int column,
QTableWidgetItem item)
Sets the item for the given row and column to item. |
void |
setItemPrototype(QTableWidgetItem item)
Sets the item prototype for the table to the specified item. |
void |
setRangeSelected(QTableWidgetSelectionRange range,
boolean select)
Selects or deselects the range depending on select. |
void |
setRowCount(int rows)
This property holds the number of rows in the table. |
void |
setVerticalHeaderItem(int row,
QTableWidgetItem item)
Sets the vertical header item for row row to item. |
void |
setVerticalHeaderLabels(java.util.List labels)
Sets the vertical header labels using labels. |
void |
sortItems(int column)
Sorts all the rows in the table widget based on column and order. |
void |
sortItems(int column,
Qt.SortOrder order)
Sorts all the rows in the table widget based on column and order. |
protected Qt.DropActions |
supportedDropActions()
Returns the drop actions supported by this view. |
QTableWidgetItem |
takeHorizontalHeaderItem(int column)
Removes the horizontal header item at column from the header without deleting it. |
QTableWidgetItem |
takeItem(int row,
int column)
Removes the item at row and column from the table without deleting it. |
QTableWidgetItem |
takeVerticalHeaderItem(int row)
Removes the vertical header item at row from the header without deleting it. |
QTableWidgetItem |
verticalHeaderItem(int row)
Returns the vertical header item for row row. |
int |
visualColumn(int logicalColumn)
Returns the visual column of the given logicalColumn. |
QRect |
visualItemRect(QTableWidgetItem item)
Returns the rectangle on the viewport occupied by the item at item. |
int |
visualRow(int logicalRow)
Returns the visual row of the given logicalRow. |
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 cellActivated
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted when the cell specified by row and column has been activated
public final QSignalEmitter.Signal2 cellChanged
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted whenever the data of the item in the cell specified by row and column has changed.
public final QSignalEmitter.Signal2 cellClicked
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.
public final QSignalEmitter.Signal2 cellDoubleClicked
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted whenever a cell in the table is double clicked. The row and column specified is the cell that was double clicked.
public final QSignalEmitter.Signal2 cellEntered
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column.
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.Signal2 cellPressed
This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: row), java.lang.Integer(named: column)>:
This signal is emitted whenever a cell the table is pressed. The row and column specified is the cell that was pressed.
public final QSignalEmitter.Signal4 currentCellChanged
This signal takes 4 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: currentRow), java.lang.Integer(named: currentColumn), java.lang.Integer(named: previousRow), java.lang.Integer(named: previousColumn)>:
This signal is emitted whenever the current cell changes. The cell specified by previousRow and previousColumn is the cell that previously had the focus, the cell specified by currentRow and currentColumn is the new current cell.
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.QTableWidgetItem(named: current), com.trolltech.qt.gui.QTableWidgetItem(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 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.QTableWidgetItem(named: item)>:
This signal is emitted when the specified item has been activated
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.QTableWidgetItem(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.QTableWidgetItem(named: item)>:
This signal is emitted whenever an item in the table is clicked. The item specified is the item that was clicked.
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.QTableWidgetItem(named: item)>:
This signal is emitted whenever an item in the table is double clicked. The item specified is the item that was double clicked.
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.QTableWidgetItem(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.QTableWidgetItem(named: item)>:
This signal is emitted whenever an item in the table is pressed. The item specified is the item that was pressed.
public final QSignalEmitter.Signal0 itemSelectionChanged
selectedItems()
, and isItemSelected().
Constructor Detail |
---|
public QTableWidget()
public QTableWidget(QWidget parent)
public QTableWidget(int rows, int columns)
public QTableWidget(int rows, int columns, QWidget parent)
Method Detail |
---|
public final QWidget cellWidget(int row, int column)
Note: The table takes ownership of the widget.
setCellWidget()
.
public final void clear()
public final void clearContents()
public final void closePersistentEditor(QTableWidgetItem item)
openPersistentEditor()
.
public final int column(QTableWidgetItem item)
public final int columnCount()
public final int currentColumn()
currentRow()
, and setCurrentCell()
.
public final QTableWidgetItem currentItem()
setCurrentItem()
.
public final int currentRow()
currentColumn()
, and setCurrentCell()
.
public final void editItem(QTableWidgetItem 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)
public final QTableWidgetItem horizontalHeaderItem(int column)
setHorizontalHeaderItem()
.
protected final com.trolltech.qt.core.QModelIndex indexFromItem(QTableWidgetItem item)
public final void insertColumn(int column)
public final void insertRow(int row)
public final QTableWidgetItem item(int row, int column)
setItem()
.
public final QTableWidgetItem itemAt(QPoint p)
item()
.
public final QTableWidgetItem itemAt(int x, int y)
QPoint
(ax, ay) in the table widget's coordinate system, or returns 0 if the specified point is not covered by an item in the table widget. item()
.
protected final QTableWidgetItem itemFromIndex(com.trolltech.qt.core.QModelIndex index)
QTableWidgetItem
assocated with the given index.
public final QTableWidgetItem itemPrototype()
setItemPrototype()
.
protected final java.util.List items(QMimeData data)
QTreeWidget
in the same process, the list is empty.
public final void openPersistentEditor(QTableWidgetItem item)
closePersistentEditor()
.
public final void removeCellWidget(int row, int column)
public final void removeColumn(int column)
public final void removeRow(int row)
public final int row(QTableWidgetItem item)
public final int rowCount()
public final void scrollToItem(QTableWidgetItem item)
public final void scrollToItem(QTableWidgetItem item, QAbstractItemView.ScrollHint hint)
public final java.util.List selectedItems()
This function returns a list of pointers to the contents of the selected cells. Use the selectedIndexes()
function to retrieve the complete selection including empty cells.
selectedIndexes()
.
public final java.util.List selectedRanges()
QTableWidgetSelectionRange
.
public final void setCellWidget(int row, int column, QWidget widget)
Note: The table takes ownership of the widget.
cellWidget()
.
public final void setColumnCount(int columns)
public final void setCurrentCell(int row, int column)
Depending on the current selection mode
, the cell may also be selected.
setCurrentItem()
, currentRow()
, and currentColumn()
.
public final void setCurrentCell(int row, int column, QItemSelectionModel.SelectionFlag[] command)
public final void setCurrentCell(int row, int column, QItemSelectionModel.SelectionFlags command)
setCurrentItem()
, currentRow()
, and currentColumn()
.
public final void setCurrentItem(QTableWidgetItem item)
Depending on the current selection mode
, the item may also be selected.
currentItem()
, and setCurrentCell()
.
public final void setCurrentItem(QTableWidgetItem item, QItemSelectionModel.SelectionFlag[] command)
public final void setCurrentItem(QTableWidgetItem item, QItemSelectionModel.SelectionFlags command)
currentItem()
, and setCurrentCell()
.
public final void setHorizontalHeaderItem(int column, QTableWidgetItem item)
horizontalHeaderItem()
.
public final void setHorizontalHeaderLabels(java.util.List labels)
public final void setItem(int row, int column, QTableWidgetItem item)
The table takes ownership of the item.
Note that if sorting is enabled (see sortingEnabled
) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem()
in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem()
will not move the row).
item()
, and takeItem()
.
public final void setItemPrototype(QTableWidgetItem item)
The table widget will use the item prototype clone function when it needs to create a new table item. For example when the user is editing editing in an empty cell. This is useful when you have a QTableWidgetItem
subclass and want to make sure that QTableWidget creates instances of your subclass.
The table takes ownership of the prototype.
itemPrototype()
.
public final void setRangeSelected(QTableWidgetSelectionRange range, boolean select)
public final void setRowCount(int rows)
public final void setVerticalHeaderItem(int row, QTableWidgetItem item)
verticalHeaderItem()
.
public final void setVerticalHeaderLabels(java.util.List labels)
public final void sortItems(int column)
public final void sortItems(int column, Qt.SortOrder order)
public final QTableWidgetItem takeHorizontalHeaderItem(int column)
public final QTableWidgetItem takeItem(int row, int column)
public final QTableWidgetItem takeVerticalHeaderItem(int row)
public final QTableWidgetItem verticalHeaderItem(int row)
setVerticalHeaderItem()
.
public final int visualColumn(int logicalColumn)
public final QRect visualItemRect(QTableWidgetItem item)
public final int visualRow(int logicalRow)
protected boolean dropMimeData(int row, int column, 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()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |