是否可以在QTreeWidget列中对数字进行排序? [英] Is it possible to sort numbers in a QTreeWidget column?
本文介绍了是否可以在QTreeWidget列中对数字进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个QTreeWidget,其中的一列填充了一些数字,如何对它们进行排序?
I have a QTreeWidget with a column filled with some numbers, how can I sort them?
如果我使用setSortingEnabled(true);我只能对字符串进行正确排序,因此我的列已排序:
If I use setSortingEnabled(true); I can sort correctly only strings, so my column is sorted:
1 10 100 2个 20 200
1 10 100 2 20 200
但这不是我想要的东西! 有建议吗?
but this is not the thing I want! Suggestions?
推荐答案
您可以对覆盖<运算符和这样的排序条件更改.
You can sort overriding the < operator and changing sort condiction like this.
class TreeWidgetItem : public QTreeWidgetItem {
public:
TreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent){}
private:
bool operator<(const QTreeWidgetItem &other)const {
int column = treeWidget()->sortColumn();
return text(column).toLower() < other.text(column).toLower();
}
};
在此示例中,它忽略了实际情况,在小写模式下面对字段.
In this example it ignore the real case, confronting fields in lowercase mode.
这篇关于是否可以在QTreeWidget列中对数字进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文