Qtablewidget 复杂表头

我也遇到过这种情况,但是自己实现headData比较复杂,我就用了最初级的方法解决,就比如你这个情况,就是创建一个最根本的Qtablewidget,它的表头为“过球”、“主管泄漏”、“全车泄露”,也就是个3列的表格,然后在每一列的第一行中添加子表格
QTableWidget *rootWidget = new QTableWidget(this);
rootWidget->setColumnCount(3);
rootWidget->setRowCount(1);
rootWidget->horizontalHeader()->setStretchLastSection(true);
rootWidget->setHorizontalHeaderLabels(QStringList() << QString::fromLocal8Bit("过球")
<< QString::fromLocal8Bit("主管泄漏") << QString::fromLocal8Bit("全车泄漏"));

QTableWidget *widget1 = new QTableWidget;
widget1->setColumnCount(2);
widget1->setRowCount(1);
widget1->horizontalHeader()->setStretchLastSection(true);
widget1->verticalHeader()->setVisible(false);
widget1->setHorizontalHeaderLabels(QStringList() << QString::fromLocal8Bit("结果")
<< QString::fromLocal8Bit("球编号"));
QTableWidget *widget2 = new QTableWidget;
widget2->setColumnCount(2);
widget2->setRowCount(1);
widget2->horizontalHeader()->setStretchLastSection(true);
widget2->verticalHeader()->setVisible(false);
widget2->setHorizontalHeaderLabels(QStringList() << QString::fromLocal8Bit("结果")
<< QString::fromLocal8Bit("漏泄量"));
QTableWidget *widget3 = new QTableWidget;
widget3->setColumnCount(2);
widget3->setRowCount(1);
widget3->horizontalHeader()->setStretchLastSection(true);
widget3->verticalHeader()->setVisible(false);
widget3->setHorizontalHeaderLabels(QStringList() << QString::fromLocal8Bit("结果")
<< QString::fromLocal8Bit("漏泄量"));
rootWidget->setCellWidget(0,0,widget1);
rootWidget->setCellWidget(0,1,widget2);
rootWidget->setCellWidget(0,2,widget3);

 

转载于:https://www.cnblogs.com/kayvanguo/p/6616182.html

你可能感兴趣的:(Qtablewidget 复杂表头)