QTableView Class Reference |
|
|
QTableView ( QWidget * parent = 0 ) | |
~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 |
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 ) |
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.
QTableView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.
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.
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(). Since both of these are plain widgets, 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().
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() or verticalHeader() and set the header's stretchLastSection property. To distribute the available space according to the space requirement of each column or row, call the view's resizeColumnsToContents() or resizeRowsToContents() functions. |
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.
QTableView is styled appropriately for each platform. The following images show how it looks on three different platforms. Go to the Qt Widget Gallery to see its appearance in other styles.
A Windows XP style table view. | A Macintosh style table view. | A Plastique style table view. |
See also QTableWidget, View Classes, QAbstractItemModel, QAbstractItemView, Chart Example, Pixelator Example, and Table Model Example.
This property holds 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.
This property was introduced in Qt 4.3.
Access functions:
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).
Access functions:
Qt::PenStyle | gridStyle () const |
void | setGridStyle ( Qt::PenStyle style ) |
This property holds 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.
Access functions:
bool | showGrid () const |
void | setShowGrid ( bool show ) |
This property holds whether sorting is enabled.
If this property is true, sorting is enabled for the table. If this property is false, sorting is not enabled. The default value is false.
Note:. Setting the property to true with setSortingEnabled() immediately triggers a call to sortByColumn() with the current sort section and order.
This property was introduced in Qt 4.2.
Access functions:
bool | isSortingEnabled () const |
void | setSortingEnabled ( bool enable ) |
See also sortByColumn().
This property holds 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.
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.
This property was introduced in Qt 4.3.
Access functions:
bool | wordWrap () const |
void | setWordWrap ( bool on ) |
Constructs a table view with a parent to represent the data.
See also QAbstractItemModel.
Destroys the table view.
Removes all row and column spans in the table view.
This function was introduced in Qt 4.4.
See also setSpan().
Returns the column in which the given x-coordinate, x, in contents coordinates is located.
Note: This function returns -1 if the given coordinate is not valid (has no column).
See also rowAt().
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.
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.
See also rowMoved().
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.
See also rowResized().
Returns the column span of the table element at (row, column). The default is 1.
This function was introduced in Qt 4.2.
See also setSpan() and rowSpan().
Returns the x-coordinate in contents coordinates of the given column.
Returns the width of the given column.
See also setColumnWidth(), resizeColumnToContents(), and rowHeight().
Reimplemented from QAbstractItemView::currentChanged().
Hide the given column.
See also showColumn() and hideRow().
Hide the given row.
See also showRow() and hideColumn().
Returns the table view's horizontal header.
See also setHorizontalHeader(), verticalHeader(), and QAbstractItemModel::headerData().
Reimplemented from 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.
See also verticalOffset().
Reimplemented from QAbstractItemView::indexAt().
Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.6-snapshot | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com