QTableView排序信号? [英] QTableView sorting signal?
问题描述
我使用QTableView
+ QStandardItemModel
来显示一些数据(数据存储在其他数据结构中),并且此表视图是可排序的.
I use QTableView
+ QStandardItemModel
to show some data (data stored in some other data structure), and this table view is sortable.
由于它是可排序的,因此在对模型进行排序时,我还需要对存储数据的顺序进行排序.我尝试为排序信号实现一个插槽,但是我不知道单击标题开始排序操作时会发出什么信号.
Since it is sortable, when sorting this model, I also need to sort the order of stored data. I try to implement a slot for the sorting signal, but I don't know what signal is emitted when clicking the header to start the sorting action.
我尝试了单击信号,但仅针对数据行而不针对headerData发出.
如果我要对QtableView
+ QStandardItemModel
排序时还要做其他事情怎么办?
I tried the clicked signal, but it's only emitted for data row, not for the headerData.
what should I do if I want to do something else while sorting the QtableView
+ QStandardItemModel
?
推荐答案
可以通过
QHeaderView * QTableView::horizontalHeader () const
现在使用获得的QHeaderView
,您可以将插槽连接到信号
Now with the obtained QHeaderView
, you can connect a slot to the signal,
void QHeaderView::sectionClicked ( int logicalIndex ) [signal].
从Qt 4.5文档中,单击某个部分时会发出此信号.该部分的逻辑索引由logicalIndex指定.请注意,还会发出sectionPressed信号.
From the Qt 4.5 documentation, This signal is emitted when a section is clicked. The section's logical index is specified by logicalIndex.Note that the sectionPressed signal will also be emitted.
希望有帮助.
这篇关于QTableView排序信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!