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

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

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

__NOTOC__

Image:qt-logo.png

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

Image:trolltech-logo.png

Содержание

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

The QTableWidget class provides an item-based table view with a default model. More...

 #include <QTableWidget>

Inherits QTableView.

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

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

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

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

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

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

[править] Сигналы

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

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

  • virtual bool dropMimeData ( int row, int column, const QMimeData * data, Qt::DropAction action )
  • QModelIndex indexFromItem ( QTableWidgetItem * item ) const
  • QTableWidgetItem * itemFromIndex ( const QModelIndex & index ) const
  • QList<QTableWidgetItem *> items ( const QMimeData * data ) const
  • virtual QMimeData * mimeData ( const QList<QTableWidgetItem *> items ) const
  • virtual QStringList mimeTypes () const
  • virtual Qt::DropActions supportedDropActions () const
  • 7 защищенных функций унаследованных от QTableView
  • 33 защищенных функций унаследованных от QAbstractItemView
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

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

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

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

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(tr("%1").arg(
         (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(QIcon(QPixmap(":/Images/cubed.png")));
     cubesHeaderItem->setTextAlignment(Qt::AlignVCenter);

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.


center center Файл:Plastique-tableview.png
A Windows XP style table widget. A Macintosh style table widget. A Plastique style table widget.

See also QTableWidgetItem, QTableView, and Model/View Programming.


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

[править]
columnCount : int

This property holds the number of columns in the table.

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

  • int columnCount () const
  • void setColumnCount ( int columns )

[править]
rowCount : int

This property holds the number of rows in the table.

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

  • int rowCount () const
  • void setRowCount ( int rows )

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

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

Creates a new table view with the given parent.

[править]
QTableWidget::QTableWidget ( int rows, int columns, QWidget * parent = 0 )

Creates a new table view with the given rows and columns, and with the given parent.

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

Destroys this QTableWidget.

[править]
void QTableWidget::cellActivated ( int row, int column ) [signal]

This signal is emitted when the cell specified by row and column has been activated

This function was introduced in Qt 4.1.

[править]
void QTableWidget::cellChanged ( int row, int column ) [signal]

This signal is emitted whenever the data of the item in the cell specified by row and column has changed.

This function was introduced in Qt 4.1.

[править]
void QTableWidget::cellClicked ( int row, int column ) [signal]

This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.

This function was introduced in Qt 4.1.

[править]
void QTableWidget::cellDoubleClicked ( int row, int column ) [signal]

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.

This function was introduced in Qt 4.1.

[править]
void QTableWidget::cellEntered ( int row, int column ) [signal]

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.

This function was introduced in Qt 4.1.

[править]
void QTableWidget::cellPressed ( int row, int column ) [signal]

This signal is emitted whenever a cell the table is pressed. The row and column specified is the cell that was pressed.

This function was introduced in Qt 4.1.

[править]
QWidget * QTableWidget::cellWidget ( int row, int column ) const

Returns the widget displayed in the cell in the given row and column.

This function was introduced in Qt 4.1.

See also setCellWidget().

[править]
void QTableWidget::clear () [slot]

Removes all items in the view. This will also remove all selections. The table dimentions stay the same.

[править]
void QTableWidget::clearContents () [slot]

Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.

This function was introduced in Qt 4.2.

[править]
void QTableWidget::closePersistentEditor ( QTableWidgetItem * item )

Closes the persistent editor for item.

See also openPersistentEditor().

[править]
int QTableWidget::column ( const QTableWidgetItem * item ) const

Returns the column for the item.

[править]
void QTableWidget::currentCellChanged ( int currentRow, int currentColumn, int previousRow, int previousColumn ) [signal]

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.

This function was introduced in Qt 4.1.

[править]
int QTableWidget::currentColumn () const

Returns the column of the current item.

See also currentRow() and setCurrentCell().

[править]
QTableWidgetItem * QTableWidget::currentItem () const

Returns the current item.

See also setCurrentItem().

[править]
void QTableWidget::currentItemChanged ( QTableWidgetItem * current, QTableWidgetItem * previous ) [signal]

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.

[править]
int QTableWidget::currentRow () const

Returns the row of the current item.

See also currentColumn() and setCurrentCell().

[править]
bool QTableWidget::dropMimeData ( int row, int column, const QMimeData * data, Qt::DropAction action ) [virtual protected]

Handles the data supplied by a drag and drop operation that ended with the given action in the given row and column. Returns true if the data and action can be handled by the model; otherwise returns false.

See also supportedDropActions().

[править]
void QTableWidget::editItem ( QTableWidgetItem * item )

Starts editing the item if it is editable.

[править]
QList< QTableWidgetItem *> QTableWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const

Finds items that matches the text using the given flags.

[править]
QTableWidgetItem * QTableWidget::horizontalHeaderItem ( int column ) const

Returns the horizontal header item for column column.

See also setHorizontalHeaderItem().

[править]
QModelIndex QTableWidget::indexFromItem ( QTableWidgetItem * item ) const [protected]

Returns the QModelIndex assocated with the given item.

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

Inserts an empty column into the table at column.

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

Inserts an empty row into the table at row.

[править]
QTableWidgetItem * QTableWidget::item ( int row, int column ) const

Returns the item for the given row and column if one has been set; otherwise returns 0.

See also setItem().

[править]
void QTableWidget::itemActivated ( QTableWidgetItem * item ) [signal]

This signal is emitted when the specified item has been activated

[править]
QTableWidgetItem * QTableWidget::itemAt ( const QPoint & point ) const

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.

See also item().

[править]
QTableWidgetItem * QTableWidget::itemAt ( int ax, int ay ) const

This is an overloaded member function, provided for convenience.

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.

See also item().

[править]
void QTableWidget::itemChanged ( QTableWidgetItem * item ) [signal]

This signal is emitted whenever the data of item has changed.

[править]
void QTableWidget::itemClicked ( QTableWidgetItem * item ) [signal]

This signal is emitted whenever an item in the table is clicked. The item specified is the item that was clicked.

[править]
void QTableWidget::itemDoubleClicked ( QTableWidgetItem * item ) [signal]

This signal is emitted whenever an item in the table is double clicked. The item specified is the item that was double clicked.

[править]
void QTableWidget::itemEntered ( QTableWidgetItem * item ) [signal]

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.

[править]
QTableWidgetItem * QTableWidget::itemFromIndex ( const QModelIndex & index ) const [protected]

Returns a pointer to the QTableWidgetItem assocated with the given index.

[править]
void QTableWidget::itemPressed ( QTableWidgetItem * item ) [signal]

This signal is emitted whenever an item in the table is pressed. The item specified is the item that was pressed.

[править]
const QTableWidgetItem * QTableWidget::itemPrototype () const

Returns the item prototype used by the table.

See also setItemPrototype().

[править]
void QTableWidget::itemSelectionChanged () [signal]

This signal is emitted whenever the selection changes.

See also selectedItems() and isItemSelected().

[править]
QList< QTableWidgetItem *> QTableWidget::items ( const QMimeData * data ) const [protected]

Returns a list of pointers to the items contained in the data object. If the object was not created by a QTreeWidget in the same process, the list is empty.

[править]
QMimeData * QTableWidget::mimeData ( const QList< QTableWidgetItem *> items ) const [virtual protected]

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.

If the list of items is empty, 0 is returned rather than a serialized empty list.

[править]
QStringList QTableWidget::mimeTypes () const [virtual protected]

Returns a list of MIME types that can be used to describe a list of tablewidget items.

See also mimeData().

[править]
void QTableWidget::openPersistentEditor ( QTableWidgetItem * item )

Opens an editor for the give item. The editor remains open after editing.

See also closePersistentEditor().

[править]
void QTableWidget::removeCellWidget ( int row, int column )

Removes the widget set on the cell indicated by row and column.

This function was introduced in Qt 4.3.

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

Removes the column column and all its items from the table.

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

Removes the row row and all its items from the table.

[править]
int QTableWidget::row ( const QTableWidgetItem * item ) const

Returns the row for the item.

[править]
void QTableWidget::scrollToItem ( const QTableWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible ) [slot]

Scrolls the view if necessary to ensure that the item is visible. The hint parameter specifies more precisely where the item should be located after the operation.

[править]
QList< QTableWidgetItem *> QTableWidget::selectedItems ()

Returns a list of all selected items.

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.

See also selectedIndexes().

[править]
QList< QTableWidgetSelectionRange> QTableWidget::selectedRanges () const

Returns a list of all selected ranges.

See also QTableWidgetSelectionRange.

[править]
void QTableWidget::setCellWidget ( int row, int column, QWidget * widget )

Sets the widget to be displayed in the cell in the given row and column.

This function was introduced in Qt 4.1.

See also cellWidget().

[править]
void QTableWidget::setCurrentCell ( int row, int column )

Sets the current cell to be the cell at position (row, column).

Depending on the current selection mode, the cell may also be selected.

This function was introduced in Qt 4.1.

See also setCurrentItem(), currentRow(), and currentColumn().

[править]
void QTableWidget::setCurrentItem ( QTableWidgetItem * item )

Sets the current item to item.

Depending on the current selection mode, the item may also be selected.

See also currentItem() and setCurrentCell().

[править]
void QTableWidget::setHorizontalHeaderItem ( int column, QTableWidgetItem * item )

Sets the horizontal header item for column column to item.

See also horizontalHeaderItem().

[править]
void QTableWidget::setHorizontalHeaderLabels ( const QStringList & labels )

Sets the horizontal header labels using labels.

[править]
void QTableWidget::setItem ( int row, int column, QTableWidgetItem * item )

Sets the item for the given row and column to 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).

See also item() and takeItem().

[править]
void QTableWidget::setItemPrototype ( const QTableWidgetItem * item )

Sets the item prototype for the table to the specified 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.

See also itemPrototype().

[править]
void QTableWidget::setRangeSelected ( const QTableWidgetSelectionRange & range, bool select )

Selects or deselects the range depending on select.

[править]
void QTableWidget::setVerticalHeaderItem ( int row, QTableWidgetItem * item )

Sets the vertical header item for row row to item.

See also verticalHeaderItem().

[править]
void QTableWidget::setVerticalHeaderLabels ( const QStringList & labels )

Sets the vertical header labels using labels.

[править]
void QTableWidget::sortItems ( int column, Qt::SortOrder order = Qt::AscendingOrder )

Sorts all the rows in the table widget based on column and order.

[править]
Qt::DropActions QTableWidget::supportedDropActions () const [virtual protected]

Returns the drop actions supported by this view.

See also Qt::DropActions.

[править]
QTableWidgetItem * QTableWidget::takeHorizontalHeaderItem ( int column )

Removes the horizontal header item at column from the header without deleting it.

This function was introduced in Qt 4.1.

[править]
QTableWidgetItem * QTableWidget::takeItem ( int row, int column )

Removes the item at row and column from the table without deleting it.

[править]
QTableWidgetItem * QTableWidget::takeVerticalHeaderItem ( int row )

Removes the vertical header item at row from the header without deleting it.

This function was introduced in Qt 4.1.

[править]
QTableWidgetItem * QTableWidget::verticalHeaderItem ( int row ) const

Returns the vertical header item for row row.

See also setVerticalHeaderItem().

[править]
int QTableWidget::visualColumn ( int logicalColumn ) const

Returns the visual column of the given logicalColumn.

[править]
QRect QTableWidget::visualItemRect ( const QTableWidgetItem * item ) const

Returns the rectangle on the viewport occupied by the item at item.

[править]
int QTableWidget::visualRow ( int logicalRow ) const

Returns the visual row of the given logicalRow.


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2