qt tableview 选择模式详解 支持不连续选中

这是官方文档的选择模式详解
QAbstractItemView::SingleSelection
1
When the user selects an item, any already-selected item becomes unselected, and the user cannot unselect the selected item by clicking on it.
QAbstractItemView::ContiguousSelection
4
When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item.
QAbstractItemView::ExtendedSelection
3
When the user selects an item in the usual way, the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. If the user presses the Shift key while clicking on an item, all items between the current item and the clicked item are selected or unselected, depending on the state of the clicked item. Multiple items can be selected by dragging the mouse over them.
QAbstractItemView::MultiSelection
2
When the user selects an item in the usual way, the selection status of that item is toggled and the other items are left alone. Multiple items can be toggled by dragging the mouse over them.
QAbstractItemView::NoSelection
0
Items cannot be selected.


单选 1 只能有一个项目被选中
连续选 4 只能够被连续选中,例如按下shift后的效果
拓展选 3 效果和ContiguousSelection一样,同时支持按键支持其他功能,ctrl,shift
多选 2 效果和按着ctrl一样,当你单击一个项目,再单击另外项目,之前的那条不会被取消选中
无法选中 0 无法被选中


    ui->tableView_showExecuteInfo->setSelectionMode(QAbstractItemView::MultiSelection);//多选
    ui->tableView_showExecuteInfo->setSelectionBehavior(QAbstractItemView::SelectRows);//每次选择一行
这是最简单的方式来选中

更好的方法是利用QMAP记入















  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值