qt qtableview 刷新列表_Qt Class之QTableWidget(持续更新)

Qt Class之QTableWidget

文档名称

Qt Class之QTableWidget

创建时间

2012-9-7

修改时间

2012-9-7

创建人

Baifx

简介(收获)

QTableWidget、QTableWidgetItem、QTableView

一、综述。

1、继承关系。

QTableWidget类:

QHeaderView类:

2、官方描述。

QTableWidget

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 useQTableViewrather 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 withsetItem():

(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 (seesetItem() 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 thesetHorizontalHeaderLabels() andsetVerticalHeaderLabels() 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 = newQTableWidgetItem(tr("Cubes"));

cubesHeaderItem->setIcon(QIcon(QPixmap(":/Images/cubed.png")));

cubesHeaderItem->setTextAlignment(Qt::AlignVCenter);

The number of rows in the table can be found withrowCount(), and the number of columns withcolumnCount(). The table can be cleared with theclear() function.

QTableWidgetItem

The QTableWidgetItem class provides an item for use with theQTableWidgetclass.

Table items are used to hold pieces of information for table widgets. Items usually contain text, icons, or checkboxes

The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3.It provides an item for use with the QTableWidget class.

Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers:

QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值