Qt:Документация 4.3.2/qtableview

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QTableView Class Reference
[модуль QtGui ]

The QTableView class provides a default model/view implementation of a table view. More...

 #include <QTableView>

Inherits QAbstractItemView.

Inherited by QTableWidget.

[править] Свойства

  • 14 свойства унаследованных от QAbstractItemView
  • 2 свойства унаследованных от QAbstractScrollArea
  • 6 свойства унаследованных от QFrame
  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 52 открытых функций унаследованных от QAbstractItemView
  • 15 открытых функций унаследованных от QAbstractScrollArea
  • 13 открытых функций унаследованных от QFrame
  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Открытые слоты

  • 9 открытых слотов унаследованных от QAbstractItemView
  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject

[править] Защищенные функции

  • 33 защищенных функций унаследованных от QAbstractItemView
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

[править] Защищенные слоты

  • 8 защищенных слотов унаследованных от QAbstractItemView
  • 1 защищенный слот унаследованный от QAbstractScrollArea
  • 1 защищенный слот унаследованный от QWidget

[править] Дополнительные унаследованные члены

  • 6 сигнала унаследованных от QAbstractItemView
  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject
  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject

[править] Подробное описание

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.


center center Файл:Plastique-tableview.png
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.


[править] Описание свойств

[править]
cornerButtonEnabled : bool

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.

Функции доступа:

  • bool isCornerButtonEnabled () const
  • void setCornerButtonEnabled ( bool enable )

[править]
gridStyle : Qt::PenStyle

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 )

[править]
showGrid : bool

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.

Функции доступа:

  • bool showGrid () const
  • void setShowGrid ( bool show )

[править]
sortingEnabled : bool

This property holds 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.

This property was introduced in Qt 4.2.

Функции доступа:

  • bool isSortingEnabled () const
  • void setSortingEnabled ( bool enable )

See also sortByColumn().

[править]
wordWrap : bool

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.

This property was introduced in Qt 4.3.

Функции доступа:

  • bool wordWrap () const
  • void setWordWrap ( bool on )

[править] Описание функций-членов

[править]
QTableView::QTableView ( QWidget * parent = 0 )

Constructs a table view with a parent to represent the data.

See also QAbstractItemModel.

[править]
QTableView::~QTableView ()

Destroys the table view.

[править]
int QTableView::columnAt ( int x ) const

Returns the column in which the given x-coordinate, x, in contents coordinates is located.

See also rowAt().

[править]
void QTableView::columnCountChanged ( int oldCount, int newCount ) [protected slot]

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.

[править]
void QTableView::columnMoved ( int column, int oldIndex, int newIndex ) [protected slot]

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().

[править]
void QTableView::columnResized ( int column, int oldWidth, int newWidth ) [protected slot]

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().

[править]
int QTableView::columnSpan ( int row, int column ) const

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().

[править]
int QTableView::columnViewportPosition ( int column ) const

Returns the x-coordinate in contents coordinates of the given column.

[править]
int QTableView::columnWidth ( int column ) const

Returns the width of the given column.

See also setColumnWidth(), resizeColumnToContents(), and rowHeight().

[править]
void QTableView::hideColumn ( int column ) [slot]

Hide the given column.

See also showColumn() and hideRow().

[править]
void QTableView::hideRow ( int row ) [slot]

Hide the given row.

See also showRow() and hideColumn().

[править]
QHeaderView * QTableView::horizontalHeader () const

Returns the table view's horizontal header.

See also setHorizontalHeader(), verticalHeader(), and QAbstractItemModel::headerData().

[править]
int QTableView::horizontalOffset () const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also verticalOffset().

[править]
QModelIndex QTableView::indexAt ( const QPoint & pos ) const [virtual]

Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.

Reimplemented from QAbstractItemView.

[править]
bool QTableView::isColumnHidden ( int column ) const

Returns true if the given column is hidden; otherwise returns false.

See also isRowHidden().

[править]
bool QTableView::isRowHidden ( int row ) const

Returns true if the given row is hidden; otherwise returns false.

See also isColumnHidden().

[править]
QModelIndex QTableView::moveCursor ( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) [virtual protected]

Moves the cursor in accordance with the given cursorAction, using the information provided by the modifiers.

Reimplemented from QAbstractItemView.

See also QAbstractItemView::CursorAction.

[править]
void QTableView::paintEvent ( QPaintEvent * event ) [virtual protected]

Paints the table on receipt of the given paint event event.

Reimplemented from QWidget.

[править]
void QTableView::resizeColumnToContents ( int column ) [slot]

Resizes the given column based on the size hints of the delegate used to render each item in the column.

[править]
void QTableView::resizeColumnsToContents () [slot]

Resizes all columns based on the size hints of the delegate used to render each item in the columns.

[править]
void QTableView::resizeRowToContents ( int row ) [slot]

Resizes the given row based on the size hints of the delegate used to render each item in the row.

[править]
void QTableView::resizeRowsToContents () [slot]

Resizes all rows based on the size hints of the delegate used to render each item in the rows.

[править]
int QTableView::rowAt ( int y ) const

Returns the row in which the given y-coordinate, y, in contents coordinates is located.

See also columnAt().

[править]
void QTableView::rowCountChanged ( int oldCount, int newCount ) [protected slot]

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.

[править]
int QTableView::rowHeight ( int row ) const

Returns the height of the given row.

See also setRowHeight(), resizeRowToContents(), and columnWidth().

[править]
void QTableView::rowMoved ( int row, int oldIndex, int newIndex ) [protected slot]

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.

See also columnMoved().

[править]
void QTableView::rowResized ( int row, int oldHeight, int newHeight ) [protected slot]

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.

See also columnResized().

[править]
int QTableView::rowSpan ( int row, int column ) const

Returns the row span of the table element at (row, column). The default is 1.

This function was introduced in Qt 4.2.

See also setSpan() and columnSpan().

[править]
int QTableView::rowViewportPosition ( int row ) const

Returns the y-coordinate in contents coordinates of the given row.

[править]
void QTableView::selectColumn ( int column ) [slot]

Selects the given column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.

See also selectRow().

[править]
void QTableView::selectRow ( int row ) [slot]

Selects the given row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.

See also selectColumn().

[править]
void QTableView::setColumnHidden ( int column, bool hide )

If hide is true the given column will be hidden; otherwise it will be shown.

See also isColumnHidden() and setRowHidden().

[править]
void QTableView::setColumnWidth ( int column, int width )

Sets the width of the given column to be width.

This function was introduced in Qt 4.1.

See also columnWidth().

[править]
void QTableView::setHorizontalHeader ( QHeaderView * header )

Sets the widget to use for the vertical header to header.

See also horizontalHeader() and setVerticalHeader().

[править]
void QTableView::setRowHeight ( int row, int height )

Sets the height of the given row to be height.

This function was introduced in Qt 4.1.

See also rowHeight().

[править]
void QTableView::setRowHidden ( int row, bool hide )

If hide is true row will be hidden, otherwise it will be shown.

See also isRowHidden() and setColumnHidden().

[править]
void QTableView::setSelection ( const QRect & rect, QItemSelectionModel::SelectionFlags flags ) [virtual protected]

Selects the items within the given rect and in accordance with the specified selection flags.

Reimplemented from QAbstractItemView.

[править]
void QTableView::setSpan ( int row, int column, int rowSpan, int columnSpan )

Sets the span of the table element at (row, column) to (rowSpan, columnSpan).

This function was introduced in Qt 4.2.

See also rowSpan() and columnSpan().

[править]
void QTableView::setVerticalHeader ( QHeaderView * header )

Sets the widget to use for the horizontal header to header.

See also verticalHeader() and setHorizontalHeader().

[править]
void QTableView::showColumn ( int column ) [slot]

Show the given column.

See also hideColumn() and showRow().

[править]
void QTableView::showRow ( int row ) [slot]

Show the given row.

See also hideRow() and showColumn().

[править]
int QTableView::sizeHintForColumn ( int column ) const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also QWidget::sizeHint and horizontalHeader().

[править]
int QTableView::sizeHintForRow ( int row ) const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also QWidget::sizeHint and verticalHeader().

[править]
void QTableView::sortByColumn ( int column, Qt::SortOrder order )

Sorts the model by the values in the given column in the given order.

This function was introduced in Qt 4.2.

See also sortingEnabled.

[править]
QHeaderView * QTableView::verticalHeader () const

Returns the table view's vertical header.

See also setVerticalHeader(), horizontalHeader(), and QAbstractItemModel::headerData().

[править]
int QTableView::verticalOffset () const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also horizontalOffset().


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2