请为我写一段QTableWidget虚表实例代码,以便我学习使用
时间: 2024-05-15 10:17:31 浏览: 12
好的,下面是一段QTableWidget虚表的示例代码:
```cpp
#include <QApplication>
#include <QTableWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tableWidget(1000, 1000); // 创建一个1000*1000的表格
// 开启虚表模式
tableWidget.setRowCount(0);
tableWidget.setColumnCount(0);
tableWidget.verticalScrollBar()->setRange(0, 0);
tableWidget.horizontalScrollBar()->setRange(0,0);
tableWidget.verticalHeader()->setDefaultSectionSize(20);
tableWidget.horizontalHeader()->setDefaultSectionSize(20);
tableWidget.verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
tableWidget.horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// 设置表格数据
for(int row = 0; row < 1000; row++) {
for(int col = 0; col < 1000; col++) {
tableWidget.setItem(row, col, new QTableWidgetItem(QString("Row %1 Col %2").arg(row+1).arg(col+1)));
}
}
tableWidget.show();
return a.exec();
}
```
上面的代码创建了一个1000*1000的表格,并开启了虚表模式,可以用于处理海量数据的显示。同时,代码还为表格填充了数据,并将表格显示出来,方便学习使用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)