排序方式在QTableWidget的QLineEdit的

问题描述 投票:0回答:1

我有一个具有QTableWidget和正常细胞的表项的组合QLineEdit。我想知道由QLineEdit列中的值在表中的数据进行排序的最佳方式。

下面是一个例子。

| customer code |    header    |    message    |
------------------------------------------------
|   QLineEdit   | normal cell  |  normal cell  |
|   QLineEdit   | normal cell  |  normal cell  |
|   QLineEdit   | normal cell  |  normal cell  |
|   QLineEdit   | normal cell  |  normal cell  |
|   QLineEdit   | normal cell  |  normal cell  |

我想排序的客户代码列,但因为它是一个QLineEdit(设定setCellWidget()),该表将不会被它的值进行排序。

我知道我可以把每一个值出来,将它们放置在一个临时对象或行和洗牌周围的行,但是这将是惊人的丑陋和缓慢的。有一个更好的方法吗?

qt qt4
1个回答
1
投票

有几种方法可以解决这个,这里有一对夫妇的想法:

  • 在你的细胞中有行他们编辑使用QTableWidgetItem ::的setText()。如果保持这一对在你的线什么的编辑内容,然后排序行为应予以保留同步时间单元格设置文本。
  • 子类QTableWidgetItem和重载<运算符,此时您可以抢行编辑并手动比较它们的值。
© www.soinside.com 2019 - 2024. All rights reserved.