参照国外的一个帖子,解决该问题:
QTreeView loses highlight when clicking on empty space.
问题:
在QTableView中,选中某个Item之后,然后点击QTableView的空白区域,Item的高亮就失去了,影响用户体验。
解决方案:
重写selectionChanged函数,如果选择为空,则不要调用基本实现。这将阻止它取消选择。 以下是您需要执行的代码:
void MyTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
   if (selected.indexes().isEmpty())
      return;
   QAbstractView::selectionChanged(selected, deselected);
}
文章的脚注信息由WordPress的wp-posturl插件自动生成

 
                 微信扫一扫,打赏作者吧~
微信扫一扫,打赏作者吧~ 
	![[整理][转载]win下网卡抓包发包库Npcap使用](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2023/08/demo_1-1024x711.jpg&w=280&h=210&zc=1)
![[转载]基础数据char,int,double,string是线程安全的吗?](http://www.jyguagua.com/wp-content/themes/begin/img/random/5.jpg)
![[整理]用c++编写的RDTSC性能计时器](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/12/rdtsc-assembly-example.jpg&w=280&h=210&zc=1)
![[整理]strcmp汇编写法](http://www.jyguagua.com/wp-content/themes/begin/img/random/15.jpg)
