Qt QTableWidget点击表头设置排序

核心代码如下:

1

2

3

4

5

6

QHeaderView *headerGoods = _nodeTableWidget->horizontalHeader();

//SortIndicator为水平标题栏文字旁边的三角指示器

headerGoods->setSortIndicator(0, Qt::AscendingOrder);

headerGoods->setSortIndicatorShown(true);

headerGoods->setClickable(true);

connect(headerGoods, SIGNAL(sectionClicked(int)), _nodeTableWidget, SLOT (sortByColumn(int)));

  首先获取标题栏,然后设置排序按钮为可显示,最后添加槽函数即可。

结果如下所示:

资源下载地址:https://download.csdn.net/download/a1317338022/10683730

猜你喜欢

转载自blog.csdn.net/a1317338022/article/details/82823069