QTableView class provides a default model/view implementation of a table view. 更多...
头: | #include <QTableView> |
qmake: | QT += widgets |
继承: | QAbstractItemView |
继承者: |
|
|
QTableView (QWidget * parent = Q_NULLPTR) | |
~QTableView () | |
void | clearSpans () |
int | columnAt (int x ) const |
int | columnSpan (int row , int column ) const |
int | columnViewportPosition (int column ) const |
int | columnWidth (int column ) const |
Qt::PenStyle | gridStyle () const |
QHeaderView * | horizontalHeader () const |
bool | isColumnHidden (int column ) const |
bool | isCornerButtonEnabled () const |
bool | isRowHidden (int row ) const |
bool | isSortingEnabled () const |
int | rowAt (int y ) const |
int | rowHeight (int row ) const |
int | rowSpan (int row , int column ) const |
int | rowViewportPosition (int row ) const |
void | setColumnHidden (int column , bool hide ) |
void | setColumnWidth (int column , int width ) |
void | setCornerButtonEnabled (bool enable ) |
void | setGridStyle (Qt::PenStyle style ) |
void | setHorizontalHeader (QHeaderView * header ) |
void | setRowHeight (int row , int height ) |
void | setRowHidden (int row , bool hide ) |
void | setSortingEnabled (bool enable ) |
void | setSpan (int row , int column , int rowSpanCount , int columnSpanCount ) |
void | setVerticalHeader (QHeaderView * header ) |
void | setWordWrap (bool on ) |
bool | showGrid () const |
void | sortByColumn (int column , Qt::SortOrder order ) |
QHeaderView * | verticalHeader () const |
bool | wordWrap () const |
virtual QModelIndex | indexAt (const QPoint & pos ) const |
virtual void | setModel (QAbstractItemModel * model ) |
virtual void | setRootIndex (const QModelIndex & index ) |
virtual void | setSelectionModel (QItemSelectionModel * selectionModel ) |
void | hideColumn (int column ) |
void | hideRow (int row ) |
void | resizeColumnToContents (int column ) |
void | resizeColumnsToContents () |
void | resizeRowToContents (int row ) |
void | resizeRowsToContents () |
void | selectColumn (int column ) |
void | selectRow (int row ) |
void | setShowGrid (bool show ) |
void | showColumn (int column ) |
void | showRow (int row ) |
virtual void | currentChanged (const QModelIndex & current , const QModelIndex & previous ) |
virtual int | horizontalOffset () const |
virtual bool | isIndexHidden (const QModelIndex & index ) const |
virtual QModelIndex | moveCursor (CursorAction cursorAction , Qt::KeyboardModifiers modifiers ) |
virtual void | paintEvent (QPaintEvent * event ) |
virtual QModelIndexList | selectedIndexes () const |
virtual void | selectionChanged (const QItemSelection & selected , const QItemSelection & deselected ) |
virtual void | setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags flags ) |
virtual int | sizeHintForColumn (int column ) const |
virtual int | sizeHintForRow (int row ) const |
virtual void | timerEvent (QTimerEvent * event ) |
virtual void | updateGeometries () |
virtual int | verticalOffset () const |
virtual QStyleOptionViewItem | viewOptions () const |
virtual QSize | viewportSizeHint () const |
void | columnCountChanged (int oldCount , int newCount ) |
void | columnMoved (int column , int oldIndex , int newIndex ) |
void | columnResized (int column , int oldWidth , int newWidth ) |
void | rowCountChanged (int oldCount , int newCount ) |
void | rowMoved (int row , int oldIndex , int newIndex ) |
void | rowResized (int row , int oldHeight , int newHeight ) |
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.
QTableView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .
QTableView implements the interfaces defined by the QAbstractItemView 类以允许它显示提供数据,通过模型派生自 QAbstractItemModel 类。
You can navigate the cells in the table by clicking on a cell with the mouse, or by using the arrow keys. Because QTableView 启用 tabKeyNavigation 默认情况下,也可以命中 Tab 和 Backtab 键以从一单元格移至另一单元格。
表格拥有的垂直 Header 头部可以获得使用 verticalHeader () 函数,和水平 Header 头部获得透过 horizontalHeader () 函数。可以找到表格中每行的高度通过使用 rowHeight ();同样,可以找到列的宽度使用 columnWidth ()。由于这两者是纯 Widget,可以隐藏它们使用 hide () 函数。
行和列可以被隐藏和展示采用 hideRow (), hideColumn (), showRow (),和 showColumn ()。可以选择它们采用 selectRow () 和 selectColumn ()。表格将展示栅格从属 showGrid 特性。
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() .
By default, the cells in a table do not expand to fill the available space.
You can make the cells fill the available space by stretching the last header section. Access the relevant header using horizontalHeader () 或 verticalHeader () and set the header's stretchLastSection 特性。 To distribute the available space according to the space requirement of each column or row, call the view's resizeColumnsToContents () 或 resizeRowsToContents () 函数。 |
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 ()。 columnAt () 和 columnViewportPosition () functions provide the equivalent conversion operations between x-coordinates and column indexes.
另请参阅 QTableWidget , 视图类 , QAbstractItemModel , QAbstractItemView , 图表范例 , 像素器范例 ,和 表格模型范例 .
This property holds whether the button in the top-left corner is enabled
若此特性为
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.
此特性是
true
在默认情况下。
该特性在 Qt 4.3 引入。
访问函数:
bool | isCornerButtonEnabled () const |
void | setCornerButtonEnabled (bool enable ) |
This property holds the pen style used to draw the grid.
This property holds the style used when drawing the grid (see showGrid ).
访问函数:
Qt::PenStyle | gridStyle () const |
void | setGridStyle (Qt::PenStyle style ) |
This property holds whether the grid is shown
若此特性为
true
a grid is drawn for the table; if the property is
false
, no grid is drawn. The default value is true.
访问函数:
bool | showGrid () const |
void | setShowGrid (bool show ) |
此特性保持是否启用排序
若此特性为
true
, sorting is enabled for the table. If this property is
false
, sorting is not enabled. The default value is false.
注意: . Setting the property to true with setSortingEnabled () immediately triggers a call to sortByColumn () with the current sort section and order.
该特性在 Qt 4.2 引入。
访问函数:
bool | isSortingEnabled () const |
void | setSortingEnabled (bool enable ) |
另请参阅 sortByColumn ().
此特性保持项文本的自动换行策略
若此特性为
true
then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is
true
在默认情况下。
Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current textElideMode .
该特性在 Qt 4.3 引入。
访问函数:
bool | wordWrap () const |
void | setWordWrap (bool on ) |
Constructs a table view with a parent to represent the data.
另请参阅 QAbstractItemModel .
Destroys the table view.
Removes all row and column spans in the table view.
该函数在 Qt 4.4 引入。
另请参阅 setSpan ().
Returns the column in which the given x-coordinate, x ,在内容坐标中定位。
注意: This function returns -1 if the given coordinate is not valid (has no column).
另请参阅 rowAt ().
[protected slot]
void
QTableView::
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 slot]
void
QTableView::
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 .
另请参阅 rowMoved ().
[protected slot]
void
QTableView::
columnResized
(
int
column
,
int
oldWidth
,
int
newWidth
)
调用此槽改变宽度为给定 column 。旧宽度的指定通过 oldWidth ,和新宽度通过 newWidth .
另请参阅 rowResized ().
Returns the column span of the table element at ( row , column )。默认为 1。
该函数在 Qt 4.2 引入。
Returns the x-coordinate in contents coordinates of the given column .
Returns the width of the given column .
另请参阅 setColumnWidth (), resizeColumnToContents (),和 rowHeight ().
[virtual protected]
void
QTableView::
currentChanged
(const
QModelIndex
&
current
, const
QModelIndex
&
previous
)
重实现自 QAbstractItemView::currentChanged ().
[slot]
void
QTableView::
hideColumn
(
int
column
)
隐藏给定 column .
另请参阅 showColumn () 和 hideRow ().
[slot]
void
QTableView::
hideRow
(
int
row
)
隐藏给定 row .
另请参阅 showRow () 和 hideColumn ().
返回表格视图的水平 Header 头。
另请参阅 setHorizontalHeader (), verticalHeader (),和 QAbstractItemModel::headerData ().
[virtual protected]
int
QTableView::
horizontalOffset
() const
重实现自 QAbstractItemView::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.
另请参阅 verticalOffset ().
[virtual]
QModelIndex
QTableView::
indexAt
(const
QPoint
&
pos
) const
重实现自 QAbstractItemView::indexAt ().
Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
返回
true
若给定
column
被隐藏;否则返回
false
.
另请参阅 isRowHidden ().
[virtual protected]
bool
QTableView::
isIndexHidden
(const
QModelIndex
&
index
) const
重实现自 QAbstractItemView::isIndexHidden ().
返回
true
若给定
row
被隐藏;否则返回
false
.
另请参阅 isColumnHidden ().
[virtual protected]
QModelIndex
QTableView::
moveCursor
(
CursorAction
cursorAction
,
Qt::KeyboardModifiers
modifiers
)
重实现自 QAbstractItemView::moveCursor ().
Moves the cursor in accordance with the given cursorAction , using the information provided by the modifiers .
另请参阅 QAbstractItemView::CursorAction .
[virtual protected]
void
QTableView::
paintEvent
(
QPaintEvent
*
event
)
重实现自 QWidget::paintEvent ().
描绘表格当收到给定描绘事件 event .
[slot]
void
QTableView::
resizeColumnToContents
(
int
column
)
Resizes the given column based on the size hints of the delegate used to render each item in the column.
注意: Only visible columns will be resized. Reimplement sizeHintForColumn () to resize hidden columns as well.
另请参阅 resizeColumnsToContents (), sizeHintForColumn (),和 QHeaderView::resizeContentsPrecision ().
[slot]
void
QTableView::
resizeColumnsToContents
()
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
另请参阅 resizeColumnToContents (), sizeHintForColumn (),和 QHeaderView::resizeContentsPrecision ().
[slot]
void
QTableView::
resizeRowToContents
(
int
row
)
Resizes the given row based on the size hints of the delegate used to render each item in the row.
另请参阅 resizeRowsToContents (), sizeHintForRow (),和 QHeaderView::resizeContentsPrecision ().
[slot]
void
QTableView::
resizeRowsToContents
()
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
另请参阅 resizeRowToContents (), sizeHintForRow (),和 QHeaderView::resizeContentsPrecision ().
返回行在给定 y 坐标 y ,在内容坐标中定位。
注意: 此函数返回 -1 若给定坐标无效 (没有行)。
另请参阅 columnAt ().
[protected slot]
void
QTableView::
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 .
返回高度为给定 row .
另请参阅 setRowHeight (), resizeRowToContents (),和 columnWidth ().
[protected slot]
void
QTableView::
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 .
另请参阅 columnMoved ().
[protected slot]
void
QTableView::
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 .
另请参阅 columnResized ().
Returns the row span of the table element at ( row , column )。默认为 1。
该函数在 Qt 4.2 引入。
另请参阅 setSpan () 和 columnSpan ().
Returns the y-coordinate in contents coordinates of the given row .
[slot]
void
QTableView::
selectColumn
(
int
column
)
选择给定 column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.
另请参阅 selectRow ().
[slot]
void
QTableView::
selectRow
(
int
row
)
选择给定 row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.
另请参阅 selectColumn ().
[virtual protected]
QModelIndexList
QTableView::
selectedIndexes
() const
重实现自 QAbstractItemView::selectedIndexes ().
[virtual protected]
void
QTableView::
selectionChanged
(const
QItemSelection
&
selected
, const
QItemSelection
&
deselected
)
重实现自 QAbstractItemView::selectionChanged ().
若 hide is true the given column will be hidden; otherwise it will be shown.
另请参阅 isColumnHidden () 和 setRowHidden ().
设置宽度为给定 column 到 width .
该函数在 Qt 4.1 引入。
另请参阅 columnWidth ().
Sets the widget to use for the horizontal header to header .
另请参阅 horizontalHeader () 和 setVerticalHeader ().
[virtual]
void
QTableView::
setModel
(
QAbstractItemModel
*
model
)
重实现自 QAbstractItemView::setModel ().
[virtual]
void
QTableView::
setRootIndex
(const
QModelIndex
&
index
)
重实现自 QAbstractItemView::setRootIndex ().
Sets the height of the given row 到 height .
该函数在 Qt 4.1 引入。
另请参阅 rowHeight ().
若 hide is true row will be hidden, otherwise it will be shown.
另请参阅 isRowHidden () 和 setColumnHidden ().
[virtual protected]
void
QTableView::
setSelection
(const
QRect
&
rect
,
QItemSelectionModel::SelectionFlags
flags
)
重实现自 QAbstractItemView::setSelection ().
Selects the items within the given rect and in accordance with the specified selection flags .
[virtual]
void
QTableView::
setSelectionModel
(
QItemSelectionModel
*
selectionModel
)
重实现自 QAbstractItemView::setSelectionModel ().
若 enable is true, enables sorting for the table and immediately trigger a call to sortByColumn () with the current sort section and order
注意: Setter 函数对于特性 sortingEnabled .
另请参阅 isSortingEnabled ().
Sets the span of the table element at ( row , column ) to the number of rows and columns specified by ( rowSpanCount , columnSpanCount ).
该函数在 Qt 4.2 引入。
另请参阅 rowSpan () 和 columnSpan ().
Sets the widget to use for the vertical header to header .
另请参阅 verticalHeader () 和 setHorizontalHeader ().
[slot]
void
QTableView::
showColumn
(
int
column
)
Show the given column .
另请参阅 hideColumn () 和 showRow ().
[slot]
void
QTableView::
showRow
(
int
row
)
Show the given row .
另请参阅 hideRow () 和 showColumn ().
[virtual protected]
int
QTableView::
sizeHintForColumn
(
int
column
) const
重实现自 QAbstractItemView::sizeHintForColumn ().
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 will be used when resizeColumnToContents () 或 QHeaderView::resizeSections () is called. If a larger column width is required by either the horizontal header or the item delegate, the larger width will be used instead.
另请参阅 QWidget::sizeHint , horizontalHeader (),和 QHeaderView::resizeContentsPrecision ().
[virtual protected]
int
QTableView::
sizeHintForRow
(
int
row
) const
重实现自 QAbstractItemView::sizeHintForRow ().
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.
另请参阅 QWidget::sizeHint , verticalHeader (),和 QHeaderView::resizeContentsPrecision ().
Sorts the model by the values in the given column 以给定 order .
该函数在 Qt 4.2 引入。
另请参阅 sortingEnabled .
[virtual protected]
void
QTableView::
timerEvent
(
QTimerEvent
*
event
)
重实现自 QObject::timerEvent ().
[virtual protected]
void
QTableView::
updateGeometries
()
重实现自 QAbstractItemView::updateGeometries ().
Returns the table view's vertical header.
另请参阅 setVerticalHeader (), horizontalHeader (),和 QAbstractItemModel::headerData ().
[virtual protected]
int
QTableView::
verticalOffset
() const
重实现自 QAbstractItemView::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.
另请参阅 horizontalOffset ().
[virtual protected]
QStyleOptionViewItem
QTableView::
viewOptions
() const
重实现自 QAbstractItemView::viewOptions ().
[virtual protected]
QSize
QTableView::
viewportSizeHint
() const