如何自动对QTreeWidget列进行排序? [英] How to automatically sort a QTreeWidget column?

查看:1425
本文介绍了如何自动对QTreeWidget列进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用QTreeWidget来显示一些简单的项目.我已经设置了可通过.setSortingEnabled(true)调用排序的列表.这样,仅当用户按下标题列时,列表才会排序,插入新项时不会自动对列表进行排序.

I'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted.

是否有一种方法可以强制在指定的列中进行自动排序,而不必在每次插入项目时都调用.sortItems(column)?
如果可能的话,我将突出显示整个已排序的列.

Is there a way to force the automatic sorting in a specified column without calling .sortItems(column) at every item insertion?
If it's possible, I would highlight the whole sorted column.

推荐答案

为此,请使用 QTreeView :: setSortingEnabled() QTreeView :: sortByColumn .只需记住在最初填充窗口小部件后将其打开,然后再进行任何批量更新以提高效率就可以在/before/之前将其关闭.

To do this, use QTreeView::setSortingEnabled() and QTreeView::sortByColumn. Just remember to turn this on /after/ you initially populate the widget, and turn it off again /before/ doing any bulk updates for efficiency.

这篇关于如何自动对QTreeWidget列进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆