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);this

相關文章
相關標籤/搜索