一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
以下是两个设置表头的不同方法:
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);

 

posted on 2024-03-18 09:59  一杯清酒邀明月  阅读(475)  评论(0编辑  收藏  举报