QTableWidget class provides an item-based table view with a default model. 更多...
头: | #include <QTableWidget> |
qmake: | QT += widgets |
继承: | QTableView |
QTableWidget (QWidget * parent = Q_NULLPTR) | |
QTableWidget (int rows , int columns , QWidget * parent = Q_NULLPTR) | |
~QTableWidget () | |
QWidget * | cellWidget (int row , int column ) const |
void | closePersistentEditor (QTableWidgetItem * item ) |
int | column (const QTableWidgetItem * item ) const |
int | columnCount () const |
int | currentColumn () const |
QTableWidgetItem * | currentItem () const |
int | currentRow () const |
void | editItem (QTableWidgetItem * item ) |
QList<QTableWidgetItem *> | findItems (const QString & text , Qt::MatchFlags flags ) const |
QTableWidgetItem * | horizontalHeaderItem (int column ) const |
QTableWidgetItem * | item (int row , int column ) const |
QTableWidgetItem * | itemAt (const QPoint & point ) const |
QTableWidgetItem * | itemAt (int ax , int ay ) const |
const QTableWidgetItem * | itemPrototype () const |
void | openPersistentEditor (QTableWidgetItem * item ) |
void | removeCellWidget (int row , int column ) |
int | row (const QTableWidgetItem * item ) const |
int | rowCount () const |
QList<QTableWidgetItem *> | selectedItems () const |
QList<QTableWidgetSelectionRange> | selectedRanges () const |
void | setCellWidget (int row , int column , QWidget * widget ) |
void | setColumnCount (int columns ) |
void | setCurrentCell (int row , int column ) |
void | setCurrentCell (int row , int column , QItemSelectionModel::SelectionFlags command ) |
void | setCurrentItem (QTableWidgetItem * item ) |
void | setCurrentItem (QTableWidgetItem * item , QItemSelectionModel::SelectionFlags command ) |
void | setHorizontalHeaderItem (int column , QTableWidgetItem * item ) |
void | setHorizontalHeaderLabels (const QStringList & labels ) |
void | setItem (int row , int column , QTableWidgetItem * item ) |
void | setItemPrototype (const QTableWidgetItem * item ) |
void | setRangeSelected (const QTableWidgetSelectionRange & range , bool select ) |
void | setRowCount (int rows ) |
void | setVerticalHeaderItem (int row , QTableWidgetItem * item ) |
void | setVerticalHeaderLabels (const QStringList & labels ) |
void | sortItems (int column , Qt::SortOrder order = Qt::AscendingOrder) |
QTableWidgetItem * | takeHorizontalHeaderItem (int column ) |
QTableWidgetItem * | takeItem (int row , int column ) |
QTableWidgetItem * | takeVerticalHeaderItem (int row ) |
QTableWidgetItem * | verticalHeaderItem (int row ) const |
int | visualColumn (int logicalColumn ) const |
QRect | visualItemRect (const QTableWidgetItem * item ) const |
int | visualRow (int logicalRow ) const |
void | clear () |
void | clearContents () |
void | insertColumn (int column ) |
void | insertRow (int row ) |
void | removeColumn (int column ) |
void | removeRow (int row ) |
void | scrollToItem (const QTableWidgetItem * item , QAbstractItemView::ScrollHint hint = EnsureVisible) |
void | cellActivated (int row , int column ) |
void | cellChanged (int row , int column ) |
void | cellClicked (int row , int column ) |
void | cellDoubleClicked (int row , int column ) |
void | cellEntered (int row , int column ) |
void | cellPressed (int row , int column ) |
void | currentCellChanged (int currentRow , int currentColumn , int previousRow , int previousColumn ) |
void | currentItemChanged (QTableWidgetItem * current , QTableWidgetItem * previous ) |
void | itemActivated (QTableWidgetItem * item ) |
void | itemChanged (QTableWidgetItem * item ) |
void | itemClicked (QTableWidgetItem * item ) |
void | itemDoubleClicked (QTableWidgetItem * item ) |
void | itemEntered (QTableWidgetItem * item ) |
void | itemPressed (QTableWidgetItem * item ) |
void | itemSelectionChanged () |
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 |
virtual void | dropEvent (QDropEvent * event ) |
virtual bool | event (QEvent * e ) |
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 .
若希望表格使用自己的数据模型,应该使用 QTableView 而不是此类。
可以采用所需行数和列数构造表格 Widget:
tableWidget = new QTableWidget(12, 3, this);
另外,可以在不给定尺寸的情况下构建表格并稍后重置尺寸:
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 () 和 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 () 函数。
另请参阅 QTableWidgetItem , QTableView ,和 模型/视图编程 .
This property holds the number of columns in the table
By default, for a table constructed without row and column counts, this property contains a value of 0.
访问函数:
int | columnCount () const |
void | setColumnCount (int columns ) |
This property holds the number of rows in the table
By default, for a table constructed without row and column counts, this property contains a value of 0.
访问函数:
int | rowCount () const |
void | setRowCount (int rows ) |
创建新的表格视图,采用给定 parent .
创建新的表格视图,采用给定 rows and columns ,和采用给定 parent .
销毁此 QTableWidget .
[signal]
void
QTableWidget::
cellActivated
(
int
row
,
int
column
)
This signal is emitted when the cell specified by row and column has been activated
该函数在 Qt 4.1 引入。
[signal]
void
QTableWidget::
cellChanged
(
int
row
,
int
column
)
此信号被发射每当单元格项数据指定通过 row and column 已改变。
该函数在 Qt 4.1 引入。
[signal]
void
QTableWidget::
cellClicked
(
int
row
,
int
column
)
This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.
该函数在 Qt 4.1 引入。
[signal]
void
QTableWidget::
cellDoubleClicked
(
int
row
,
int
column
)
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.
该函数在 Qt 4.1 引入。
[signal]
void
QTableWidget::
cellEntered
(
int
row
,
int
column
)
This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column .
此信号才被发射当 mouseTracking 被打开,或当移入项时按下鼠标按钮。
该函数在 Qt 4.1 引入。
[signal]
void
QTableWidget::
cellPressed
(
int
row
,
int
column
)
This signal is emitted whenever a cell in the table is pressed. The row and column specified is the cell that was pressed.
该函数在 Qt 4.1 引入。
返回单元格显示 Widget,在给定 row and column .
注意: 表格拥有 Widget 的所有权。
该函数在 Qt 4.1 引入。
另请参阅 setCellWidget ().
[slot]
void
QTableWidget::
clear
()
Removes all items in the view. This will also remove all selections and headers. If you don't want to remove the headers, use QTableWidget::clearContents (). The table dimensions stay the same.
[slot]
void
QTableWidget::
clearContents
()
Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.
该函数在 Qt 4.2 引入。
关闭持久编辑器为 item .
另请参阅 openPersistentEditor ().
返回列号为 item .
返回列数。
注意: Getter 函数对于特性 columnCount .
另请参阅 setColumnCount ().
[signal]
void
QTableWidget::
currentCellChanged
(
int
currentRow
,
int
currentColumn
,
int
previousRow
,
int
previousColumn
)
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.
该函数在 Qt 4.1 引入。
返回当前项的列号。
另请参阅 currentRow () 和 setCurrentCell ().
返回当前项。
另请参阅 setCurrentItem ().
[signal]
void
QTableWidget::
currentItemChanged
(
QTableWidgetItem
*
current
,
QTableWidgetItem
*
previous
)
此信号被发射每当当前项改变。 previous item is the item that previously had the focus, current 是新的当前项。
返回当前项的行号。
另请参阅 currentColumn () 和 setCurrentCell ().
[virtual protected]
void
QTableWidget::
dropEvent
(
QDropEvent
*
event
)
重实现自 QWidget::dropEvent ().
[virtual protected]
bool
QTableWidget::
dropMimeData
(
int
row
,
int
column
, const
QMimeData
*
data
,
Qt::DropAction
action
)
处理
data
提供通过拖放操作结束按给定
action
以给定
row
and
column
。返回
true
if the data and action can be handled by the model; otherwise returns
false
.
另请参阅 supportedDropActions ().
开始编辑 item 若它可编辑。
[virtual protected]
bool
QTableWidget::
event
(
QEvent
*
e
)
重实现自 QObject::event ().
Finds items that matches the text 使用给定 flags .
Returns the horizontal header item for column, column , if one has been set; otherwise returns 0.
另请参阅 setHorizontalHeaderItem ().
[protected]
QModelIndex
QTableWidget::
indexFromItem
(
QTableWidgetItem
*
item
) const
返回 QModelIndex 关联给定 item .
[slot]
void
QTableWidget::
insertColumn
(
int
column
)
把空列插入表格,位置 column .
[slot]
void
QTableWidget::
insertRow
(
int
row
)
把空行插入表格,位置 row .
返回项为给定 row and column if one has been set; otherwise returns 0.
另请参阅 setItem ().
[signal]
void
QTableWidget::
itemActivated
(
QTableWidgetItem
*
item
)
此信号被发射当指定 item has been activated
Returns a pointer to the item at the given point , or returns 0 if point is not covered by an item in the table widget.
另请参阅 item ().
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.
另请参阅 item ().
[signal]
void
QTableWidget::
itemChanged
(
QTableWidgetItem
*
item
)
此信号被发射每当 item 的数据已改变。
[signal]
void
QTableWidget::
itemClicked
(
QTableWidgetItem
*
item
)
This signal is emitted whenever an item in the table is clicked. The item specified is the item that was clicked.
[signal]
void
QTableWidget::
itemDoubleClicked
(
QTableWidgetItem
*
item
)
This signal is emitted whenever an item in the table is double clicked. The item specified is the item that was double clicked.
[signal]
void
QTableWidget::
itemEntered
(
QTableWidgetItem
*
item
)
此信号被发射当鼠标光标进入项时。 item is the item entered.
此信号才被发射当 mouseTracking 被打开,或当移入项时按下鼠标按钮。
[protected]
QTableWidgetItem
*QTableWidget::
itemFromIndex
(const
QModelIndex
&
index
) const
返回指针指向 QTableWidgetItem 关联给定 index .
[signal]
void
QTableWidget::
itemPressed
(
QTableWidgetItem
*
item
)
This signal is emitted whenever an item in the table is pressed. The item specified is the item that was pressed.
Returns the item prototype used by the table.
另请参阅 setItemPrototype ().
[signal]
void
QTableWidget::
itemSelectionChanged
()
此信号被发射每当选定改变时。
另请参阅 selectedItems () 和 QTableWidgetItem::isSelected ().
[protected]
QList
<
QTableWidgetItem
*> QTableWidget::
items
(const
QMimeData
*
data
) const
返回的指针列表项包含在 data 对象。若未创建对象通过 QTreeWidget 在同一过程中,列表为空。
[virtual protected]
QMimeData
*QTableWidget::
mimeData
(const
QList
<
QTableWidgetItem
*>
items
) const
返回的对象包含序列化描述为指定 items 。用于描述项的格式获取自 mimeTypes () 函数。
If the list of items is empty, 0 is returned rather than a serialized empty list.
[virtual protected]
QStringList
QTableWidget::
mimeTypes
() const
Returns a list of MIME types that can be used to describe a list of tablewidget items.
另请参阅 mimeData ().
Opens an editor for the give item 。编辑器仍然打开在编辑之后。
另请参阅 closePersistentEditor ().
Removes the widget set on the cell indicated by row and column .
该函数在 Qt 4.3 引入。
[slot]
void
QTableWidget::
removeColumn
(
int
column
)
移除列 column 及表格中的所有项。
[slot]
void
QTableWidget::
removeRow
(
int
row
)
移除行 row 及表格中的所有项。
Returns the row for the item .
Returns the number of rows.
注意: Getter 函数对于特性 rowCount .
另请参阅 setRowCount ().
[slot]
void
QTableWidget::
scrollToItem
(const
QTableWidgetItem
*
item
,
QAbstractItemView::ScrollHint
hint
= EnsureVisible)
卷动视图若有必要以确保 item is visible. The hint parameter specifies more precisely where the item 应位于在操作后。
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 包括 empty cells.
另请参阅 selectedIndexes ().
Returns a list of all selected ranges.
另请参阅 QTableWidgetSelectionRange .
设置给定 widget to be displayed in the cell in the given row and column , passing the ownership of the widget to the table.
If cell widget A is replaced with cell widget B, cell widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.
setCellWidget(row, column, new QLineEdit); ... setCellWidget(row, column, new QTextEdit);
该函数在 Qt 4.1 引入。
另请参阅 cellWidget ().
Sets the number of columns in this table's model to columns . If this is less than columnCount (), the data in the unwanted columns is discarded.
注意: Setter 函数对于特性 columnCount .
另请参阅 columnCount () 和 setRowCount ().
Sets the current cell to be the cell at position ( row , column ).
Depending on the current 选定模式 , the cell may also be selected.
该函数在 Qt 4.1 引入。
另请参阅 setCurrentItem (), currentRow (),和 currentColumn ().
Sets the current cell to be the cell at position ( row , column ), using the given command .
该函数在 Qt 4.4 引入。
另请参阅 setCurrentItem (), currentRow (),和 currentColumn ().
将当前项设为 item .
除非选定模式为 NoSelection ,项还被选中。
另请参阅 currentItem () 和 setCurrentCell ().
Sets the current item to be item ,使用给定 command .
该函数在 Qt 4.4 引入。
另请参阅 currentItem () 和 setCurrentCell ().
Sets the horizontal header item for column column to item . If necessary, the column count is increased to fit the item. The previous header item (if there was one) is deleted.
另请参阅 horizontalHeaderItem ().
设置水平 Header 头标签,使用 labels .
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).
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 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.
另请参阅 itemPrototype ().
Selects or deselects the range depending on select .
Sets the number of rows in this table's model to rows . If this is less than rowCount (), the data in the unwanted rows is discarded.
注意: Setter 函数对于特性 rowCount .
另请参阅 rowCount () 和 setColumnCount ().
Sets the vertical header item for row row to item .
另请参阅 verticalHeaderItem ().
Sets the vertical header labels using labels .
Sorts all the rows in the table widget based on column and order .
[virtual protected]
Qt::DropActions
QTableWidget::
supportedDropActions
() const
返回由此视图所支持的掉落动作。
另请参阅 Qt::DropActions .
Removes the horizontal header item at column 从头部而不删除它。
该函数在 Qt 4.1 引入。
移除项在 row and column from the table without deleting it.
移除垂直 Header 头部项在 row 从头部而不删除它。
该函数在 Qt 4.1 引入。
Returns the vertical header item for row row .
另请参阅 setVerticalHeaderItem ().
Returns the visual column of the given logicalColumn .
返回项所占据的视口矩形为 item .
Returns the visual row of the given logicalRow .