Qt QTableView、QTableWidget设置表头


以下是两个设置表头的不同方法:
QTableWidget: 1 //设置表头 2 QStringList heardList;//表头 3 heardList << QString::frLocal8Bit("接收")<<QString::frLocal8Bit("发送"); 4 ui.tableWidget>setColumnCount(heardListount()); 5 ui.tableWidget>setHorizontalHeaderLabels(heardList);

QTableView:

1 QStringList heardList;//表头 2 heardList << QString::frLocal8Bit("接收")<<QString::frLocal8Bit("发送"); 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);



上一篇:Qt 两种方法解决Qt使用qss对QWidget无效的问题

下一篇:C++11标准模板(STL) 算法(std::reverse)


Qt
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图