QT QTableView 取消点击行高亮保留边框
时间: 2024-10-19 22:03:33 浏览: 76
在Qt中的QTableView组件中,默认情况下,当用户单击一行时,该行会被选中并高亮显示。如果你想要取消这种高亮效果,同时保持边框显示,可以使用`setAlternatingRowColors()`和`setSelectionBehavior()`方法来定制样式。
首先,通过`setAlternatingRowColors(false)`设置行的交替颜色模式为关闭,这将消除默认的高亮效果:
```cpp
yourTableView->setAlternatingRowColors(false);
```
接下来,使用`setSelectionBehavior(QTableWidget::NoSelection)`设置选择行为为无选中状态:
```cpp
yourTableView->setSelectionBehavior(QTableWidget::NoSelection);
```
这样,当你点击行时,它不会变色,但仍保留着边框。如果你还想保持鼠标悬停时的选中效果,可以只禁用单击触发的高亮,而保留其他交互如双击、右键菜单等操作时的选中外观:
```cpp
yourTableView->setSelectionMode(QAbstractItemView::NoSelection);
yourTableView->setSelectionMode(QAbstractItemView::SingleSelectionOnMouseRelease);
```
阅读全文
相关推荐


















