以下是两个设置表头的不同方法:
QTableWidget:
1 //设置表头 2 QStringList heardList;//表头 3 heardList << QString::fromLocal8Bit("接收")<<QString::fromLocal8Bit("发送"); 4 ui.tableWidget>setColumnCount(heardList.count()); 5 ui.tableWidget->setHorizontalHeaderLabels(heardList);
QTableView:
1 QStringList heardList;//表头 2 heardList << QString::fromLocal8Bit("接收")<<QString::fromLocal8Bit("发送"); 3 QHeaderView *hearview = new QHeaderView(Qt::Horizontal); 4 QStandardItemModel* model = new QStandardItemModel; 5 model->setHorizontalHeaderLabels(heardList); 6 hearview->setModel(model); 7 hearview->setSectionResizeMode(QHeaderView::Stretch); //先自适应宽度 8 hearview->setSectionResizeMode(0, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列 9 ui.tableView->setHorizontalHeader(hearview);
标签:hearview,QTableWidget,表头,QTableView,heardList,设置 From: https://www.cnblogs.com/ybqjymy/p/18079744