|
|
||||||||||
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.QTableView
public class QTableView
The QTableView class provides a default model/view implementation of a table view.
A QTableView implements a table view that displays items from a model. This class is used to provide standard tables that were previously provided by the QTable class, but using the more flexible approach provided by Qt's model/view architecture.
The QTableView class is one of the Model/View Classes and is part of Qt's model/view framework.
You can navigate the cells in the table by clicking on a cell with the mouse, or by using the arrow keys. Because QTableView enables tabKeyNavigation by default, you can also hit Tab and Backtab to move from cell to cell.
QTableView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.
The table has a vertical header that can be obtained using the verticalHeader function, and a horizontal header that is available through the horizontalHeader function. The height of each row in the table can be found by using rowHeight; similarly, the width of columns can be found using columnWidth. They are both just QWidgets so you can hide either of them using their hide functions.
Rows and columns can be hidden and shown with hideRow, hideColumn, showRow, and showColumn. They can be selected with selectRow and selectColumn. The table will show a grid depending on the showGrid property.
The items shown in a table view, like those in the other item views, are rendered and edited using standard delegates. However, for some tasks it is sometimes useful to be able to insert widgets in a table instead. Widgets are set for particular indexes with the setIndexWidget() function, and later retrieved with indexWidget().
For some specialized forms of tables it is useful to be able to convert between row and column indexes and widget coordinates. The rowAt function provides the y-coordinate within the view of the specified row; the row index can be used to obtain a corresponding y-coordinate with rowViewportPosition. The columnAt and columnViewportPosition functions provide the equivalent conversion operations between x-coordinates and column indexes.
![]() | ![]() | ![]() |
A Windows XP style table view. | A Macintosh style table view. | A Plastique style table view. |
Example
,
Example
,
Model 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.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 |
---|
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 | |
---|---|
QTableView()
Equivalent to QTableView(0). |
|
QTableView(QWidget parent)
Constructs a table view with a parent to represent the data. |
Method Summary | |
---|---|
int |
columnAt(int x)
Returns the column in which the given x-coordinate, x, in contents coordinates is located. |
protected void |
columnCountChanged(int oldCount,
int newCount)
This slot is called whenever columns are added or deleted. |
protected void |
columnMoved(int column,
int oldIndex,
int newIndex)
This slot is called to change the index of the given column in the table view. |
protected void |
columnResized(int column,
int oldWidth,
int newWidth)
This slot is called to change the width of the given column. |
int |
columnSpan(int row,
int column)
Returns the column span of the table element at (row, column). |
int |
columnViewportPosition(int column)
Returns the x-coordinate in contents coordinates of the given column. |
int |
columnWidth(int column)
Returns the width of the given column. |
protected void |
currentChanged(QModelIndex current,
QModelIndex previous)
This slot is called when a new item becomes the current item. |
static QTableView |
fromNativePointer(QNativePointer nativePointer)
This function returns the QTableView instance pointed to by nativePointer |
Qt.PenStyle |
gridStyle()
Returns the pen style used to draw the grid.. |
void |
hideColumn(int column)
Hide the given column. |
void |
hideRow(int row)
Hide the given row. |
QHeaderView |
horizontalHeader()
Returns the table view's horizontal header. |
protected int |
horizontalOffset()
Returns the horizontal offset of the items in the table view. |
protected void |
horizontalScrollbarAction(int action)
|
QModelIndex |
indexAt(QPoint p)
Returns the index position of the model item corresponding to the table item at position p in contents coordinates. |
boolean |
isColumnHidden(int column)
Returns true if the given column is hidden; otherwise returns false. |
boolean |
isCornerButtonEnabled()
Returns whether the button in the top-left corner is enabled. |
protected boolean |
isIndexHidden(QModelIndex index)
Returns true if the item referred to by the given index is hidden in the view, otherwise returns false. |
boolean |
isRowHidden(int row)
Returns true if the given row is hidden; otherwise returns false. |
boolean |
isSortingEnabled()
Returns whether sorting is enabled. |
protected QModelIndex |
moveCursor(QAbstractItemView.CursorAction cursorAction,
Qt.KeyboardModifiers modifiers)
Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers. |
protected void |
paintEvent(QPaintEvent e)
Paints the table on receipt of the given paint event e. |
void |
resizeColumnsToContents()
Resizes all columns based on the size hints of the delegate used to render each item in the columns. |
void |
resizeColumnToContents(int column)
Resizes the given column based on the size hints of the delegate used to render each item in the column. |
void |
resizeRowsToContents()
Resizes all rows based on the size hints of the delegate used to render each item in the rows. |
void |
resizeRowToContents(int row)
Resizes the given row based on the size hints of the delegate used to render each item in the row. |
int |
rowAt(int y)
Returns the row in which the given y-coordinate, y, in contents coordinates is located. |
protected void |
rowCountChanged(int oldCount,
int newCount)
This slot is called whenever rows are added or deleted. |
int |
rowHeight(int row)
Returns the height of the given row. |
protected void |
rowMoved(int row,
int oldIndex,
int newIndex)
This slot is called to change the index of the given row in the table view. |
protected void |
rowResized(int row,
int oldHeight,
int newHeight)
This slot is called to change the height of the given row. |
int |
rowSpan(int row,
int column)
Returns the row span of the table element at (row, column). |
int |
rowViewportPosition(int row)
Returns the y-coordinate in contents coordinates of the given row. |
protected void |
scrollContentsBy(int dx,
int dy)
This virtual handler is called when the scroll bars are moved by dx, dy, and consequently the viewport's contents should be scrolled accordingly. |
void |
scrollTo(QModelIndex index,
QAbstractItemView.ScrollHint hint)
Scrolls the view if necessary to ensure that the item at index is visible. |
void |
selectColumn(int column)
Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected. |
protected java.util.List<QModelIndex> |
selectedIndexes()
This convenience function returns a list of all selected and non-hidden item indexes in the view. |
protected void |
selectionChanged(QItemSelection selected,
QItemSelection deselected)
This slot is called when the selection is changed. |
void |
selectRow(int row)
Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected. |
void |
setColumnHidden(int column,
boolean hide)
If hide is true the given column will be hidden; otherwise it will be shown. |
void |
setColumnWidth(int column,
int width)
Sets the width of the given column to be width. |
void |
setCornerButtonEnabled(boolean enable)
Sets whether the button in the top-left corner is enabled to enable. |
void |
setGridStyle(Qt.PenStyle style)
Sets the pen style used to draw the grid. |
void |
setHorizontalHeader(QHeaderView header)
Sets the widget to use for the vertical header to header. |
void |
setModel(QAbstractItemModel model)
Sets the model for the view to present. |
void |
setRootIndex(QModelIndex index)
Sets the root item to the item at the given index. |
void |
setRowHeight(int row,
int height)
Sets the height of the given row to be height. |
void |
setRowHidden(int row,
boolean hide)
If hide is true row will be hidden, otherwise it will be shown. |
protected void |
setSelection(QRect rect,
QItemSelectionModel.SelectionFlags command)
Selects the items within the given rect and in accordance with the specified selection command. |
void |
setSelectionModel(QItemSelectionModel selectionModel)
Sets the current selection model to the given selectionModel. |
void |
setShowGrid(boolean show)
Sets whether the grid is shown to show. |
void |
setSortingEnabled(boolean enable)
Sets whether sorting is enabled to enable. |
void |
setSpan(int row,
int column,
int rowSpan,
int columnSpan)
Sets the span of the table element at (row, column) to (rowSpan, columnSpan). |
void |
setVerticalHeader(QHeaderView header)
Sets the widget to use for the horizontal header to header. |
void |
setWordWrap(boolean on)
Sets the item text word-wrapping policy to on. |
void |
showColumn(int column)
Show the given column. |
boolean |
showGrid()
Returns whether the grid is shown. |
void |
showRow(int row)
Show the given row. |
int |
sizeHintForColumn(int column)
Returns the size hint for the given column's width or -1 if there is no model. |
int |
sizeHintForRow(int row)
Returns the size hint for the given row's height or -1 if there is no model. |
void |
sortByColumn(int column,
Qt.SortOrder order)
Sorts the model by the values in the given column in the given order. |
protected void |
timerEvent(QTimerEvent event)
This function is called with the given event when a timer event is sent to the widget. |
protected void |
updateGeometries()
|
QHeaderView |
verticalHeader()
Returns the table view's vertical header. |
protected int |
verticalOffset()
Returns the vertical offset of the items in the table view. |
protected void |
verticalScrollbarAction(int action)
|
protected QStyleOptionViewItem |
viewOptions()
Returns a QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc. |
QRect |
visualRect(QModelIndex index)
Returns the rectangle on the viewport occupied by the item at index. |
protected QRegion |
visualRegionForSelection(QItemSelection selection)
Returns the region from the viewport of the items in the given selection. |
boolean |
wordWrap()
Returns the item text word-wrapping policy. |
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 |
Constructor Detail |
---|
public QTableView()
Equivalent to QTableView(0).
public QTableView(QWidget parent)
Constructs a table view with a parent to represent the data.
Method Detail |
---|
public final int columnAt(int x)
Returns the column in which the given x-coordinate, x, in contents coordinates is located.
protected final void columnCountChanged(int oldCount, int newCount)
This slot is called whenever columns are added or deleted. The previous number of columns is specified by oldCount, and the new number of columns is specified by newCount.
protected final void columnMoved(int column, int oldIndex, int newIndex)
This slot is called to change the index of the given column in the table view. The old index is specified by oldIndex, and the new index by newIndex.
protected final void columnResized(int column, int oldWidth, int newWidth)
This slot is called to change the width of the given column. The old width is specified by oldWidth, and the new width by newWidth.
public final int columnSpan(int row, int column)
Returns the column span of the table element at (row, column). The default is 1.
public final int columnViewportPosition(int column)
Returns the x-coordinate in contents coordinates of the given column.
public final int columnWidth(int column)
Returns the width of the given column.
public final Qt.PenStyle gridStyle()
Returns the pen style used to draw the grid..
This property holds the style used when drawing the grid (see showGrid).
public final void hideColumn(int column)
Hide the given column.
public final void hideRow(int row)
Hide the given row.
public final QHeaderView horizontalHeader()
Returns the table view's horizontal header.
public final boolean isColumnHidden(int column)
Returns true if the given column is hidden; otherwise returns false.
public final boolean isCornerButtonEnabled()
Returns whether the button in the top-left corner is enabled.
If this property is true then button in the top-left corner of the table view is enabled. Clicking on this button will select all the cells in the table view.
This property is true by default.
public final boolean isRowHidden(int row)
Returns true if the given row is hidden; otherwise returns false.
public final boolean isSortingEnabled()
Returns whether sorting is enabled.
If this property is true, sorting is enabled for the table; if the property is false, sorting is not enabled. The default value is false.
public final void resizeColumnToContents(int column)
Resizes the given column based on the size hints of the delegate used to render each item in the column.
public final void resizeColumnsToContents()
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
public final void resizeRowToContents(int row)
Resizes the given row based on the size hints of the delegate used to render each item in the row.
public final void resizeRowsToContents()
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
public final int rowAt(int y)
Returns the row in which the given y-coordinate, y, in contents coordinates is located.
protected final void rowCountChanged(int oldCount, int newCount)
This slot is called whenever rows are added or deleted. The previous number of rows is specified by oldCount, and the new number of rows is specified by newCount.
public final int rowHeight(int row)
Returns the height of the given row.
protected final void rowMoved(int row, int oldIndex, int newIndex)
This slot is called to change the index of the given row in the table view. The old index is specified by oldIndex, and the new index by newIndex.
protected final void rowResized(int row, int oldHeight, int newHeight)
This slot is called to change the height of the given row. The old height is specified by oldHeight, and the new height by newHeight.
public final int rowSpan(int row, int column)
Returns the row span of the table element at (row, column). The default is 1.
public final int rowViewportPosition(int row)
Returns the y-coordinate in contents coordinates of the given row.
public final void selectColumn(int column)
Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.
public final void selectRow(int row)
Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.
public final void setColumnHidden(int column, boolean hide)
If hide is true the given column will be hidden; otherwise it will be shown.
public final void setColumnWidth(int column, int width)
Sets the width of the given column to be width.
public final void setCornerButtonEnabled(boolean enable)
Sets whether the button in the top-left corner is enabled to enable.
If this property is true then button in the top-left corner of the table view is enabled. Clicking on this button will select all the cells in the table view.
This property is true by default.
public final void setGridStyle(Qt.PenStyle style)
Sets the pen style used to draw the grid. to style.
This property holds the style used when drawing the grid (see showGrid).
public final void setHorizontalHeader(QHeaderView header)
Sets the widget to use for the vertical header to header.
public final void setRowHeight(int row, int height)
Sets the height of the given row to be height.
public final void setRowHidden(int row, boolean hide)
If hide is true row will be hidden, otherwise it will be shown.
public final void setShowGrid(boolean show)
Sets whether the grid is shown to show.
If this property is true a grid is drawn for the table; if the property is false, no grid is drawn. The default value is true.
public final void setSortingEnabled(boolean enable)
Sets whether sorting is enabled to enable.
If this property is true, sorting is enabled for the table; if the property is false, sorting is not enabled. The default value is false.
public final void setSpan(int row, int column, int rowSpan, int columnSpan)
Sets the span of the table element at (row, column) to (rowSpan, columnSpan).
public final void setVerticalHeader(QHeaderView header)
Sets the widget to use for the horizontal header to header.
public final void setWordWrap(boolean on)
Sets the item text word-wrapping policy to on.
If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.
public final void showColumn(int column)
Show the given column.
public final boolean showGrid()
Returns whether the grid is shown.
If this property is true a grid is drawn for the table; if the property is false, no grid is drawn. The default value is true.
public final void showRow(int row)
Show the given row.
public final void sortByColumn(int column, Qt.SortOrder order)
Sorts the model by the values in the given column in the given order.
public final QHeaderView verticalHeader()
Returns the table view's vertical header.
public final boolean wordWrap()
Returns the item text word-wrapping policy.
If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.
protected void currentChanged(QModelIndex current, QModelIndex previous)
This slot is called when a new item becomes the current item. The previous current item is specified by the previous index, and the new item by the current index.
If you want to know about changes to items see the dataChanged signal.
currentChanged
in class QAbstractItemView
protected int horizontalOffset()
Returns the horizontal offset of the items in the table view.
Note that the table view uses the horizontal header section positions to determine the positions of columns in the view.
horizontalOffset
in class QAbstractItemView
protected void horizontalScrollbarAction(int action)
horizontalScrollbarAction
in class QAbstractItemView
public QModelIndex indexAt(QPoint p)
Returns the index position of the model item corresponding to the table item at position p in contents coordinates.
indexAt
in class QAbstractItemView
protected boolean isIndexHidden(QModelIndex index)
Returns true if the item referred to by the given index is hidden in the view, otherwise returns false.
Hiding is a view specific feature. For example in TableView a column can be marked as hidden or a row in the TreeView.
In the base class this is a pure virtual function.
isIndexHidden
in class QAbstractItemView
protected QModelIndex moveCursor(QAbstractItemView.CursorAction cursorAction, Qt.KeyboardModifiers modifiers)
Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers.
moveCursor
in class QAbstractItemView
protected void paintEvent(QPaintEvent e)
Paints the table on receipt of the given paint event e.
paintEvent
in class QAbstractScrollArea
protected void scrollContentsBy(int dx, int dy)
This virtual handler is called when the scroll bars are moved by dx, dy, and consequently the viewport's contents should be scrolled accordingly.
The default implementation simply calls update on the entire viewport, subclasses can reimplement this handler for optimization purposes, or - like QScrollArea - to move a contents widget. The parameters dx and dy are there for convenience, so that the class knows how much should be scrolled (useful e.g. when doing pixel-shifts). You may just as well ignore these values and scroll directly to the position the scroll bars indicate.
Calling this function in order to scroll programmatically is an error, use the scroll bars instead (e.g. by calling QScrollBar::setValue() directly).
scrollContentsBy
in class QAbstractScrollArea
public void scrollTo(QModelIndex index, QAbstractItemView.ScrollHint hint)
Scrolls the view if necessary to ensure that the item at index is visible. The view will try to position the item according to the given hint.
In the base class this is a pure virtual function.
scrollTo
in class QAbstractItemView
protected java.util.List<QModelIndex> selectedIndexes()
This convenience function returns a list of all selected and non-hidden item indexes in the view. The list contains no duplicates, and is not sorted.
The default implementation does nothing.
selectedIndexes
in class QAbstractItemView
protected void selectionChanged(QItemSelection selected, QItemSelection deselected)
This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected, and the new selection by selected.
selectionChanged
in class QAbstractItemView
public 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 void setRootIndex(QModelIndex index)
Sets the root item to the item at the given index.
setRootIndex
in class QAbstractItemView
protected void setSelection(QRect rect, QItemSelectionModel.SelectionFlags command)
Selects the items within the given rect and in accordance with the specified selection command.
setSelection
in class QAbstractItemView
public void setSelectionModel(QItemSelectionModel selectionModel)
Sets the current selection model to the given selectionModel.
Note that, if you call setModel after this function, the given selectionModel will be replaced by a one created by the view.
setSelectionModel
in class QAbstractItemView
public int sizeHintForColumn(int column)
Returns the size hint for the given column's width or -1 if there is no model.
If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the table's horizontal header.
If you reimplement this function in a subclass, note that the value you return is only used when resizeColumnToContents is called. In that case, if a larger column width is required by either the horizontal header or the item delegate, that width will be used instead.
sizeHintForColumn
in class QAbstractItemView
public int sizeHintForRow(int row)
Returns the size hint for the given row's height or -1 if there is no model.
If you need to set the height of a given row to a fixed value, call QHeaderView::resizeSection() on the table's vertical header.
If you reimplement this function in a subclass, note that the value you return is only used when resizeRowToContents is called. In that case, if a larger row height is required by either the vertical header or the item delegate, that width will be used instead.
sizeHintForRow
in class QAbstractItemView
protected void timerEvent(QTimerEvent event)
This function is called with the given event when a timer event is sent to the widget.
timerEvent
in class QAbstractItemView
protected void updateGeometries()
updateGeometries
in class QAbstractItemView
protected int verticalOffset()
Returns the vertical offset of the items in the table view.
Note that the table view uses the vertical header section positions to determine the positions of rows in the view.
verticalOffset
in class QAbstractItemView
protected void verticalScrollbarAction(int action)
verticalScrollbarAction
in class QAbstractItemView
protected QStyleOptionViewItem viewOptions()
Returns a QStyleOptionViewItem structure populated with the view's palette, font, state, alignments etc.
viewOptions
in class QAbstractItemView
public QRect visualRect(QModelIndex index)
Returns the rectangle on the viewport occupied by the item at index.
If your item is displayed in several areas then visualRect should return the primary area that contains index and not the complete area that index might encompasses, touch or cause drawing.
In the base class this is a pure virtual function.
visualRect
in class QAbstractItemView
protected QRegion visualRegionForSelection(QItemSelection selection)
Returns the region from the viewport of the items in the given selection.
In the base class this is a pure virtual function.
visualRegionForSelection
in class QAbstractItemView
public static QTableView 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 |