pyqt -qtableWidget拖动/移动列后获取标头标签
我有一个QTableWidget,我填充了来自SQL的数据 - 我使视图中的列重新排序以使
self.horizontalHeader().setSectionsMovable(True)
用户完美的体验,我创建了很多代码,用户可以决定他想通过两个列表框的他想看到的列,一个显示桌子上的标头已经在SQL表中可见的所有标题。用户可以切换向右的列,并使它们可见。用户还可以将元素上下放置在列中,以从列重新排序标题。对于可见的列列表,我必须获得一个列表,其中包含所有可见标头 - 但我只有一个问题: 当用户将“ ID”之类的标头拖动到第一个位置
,我想获得全部标题作为for循环中的列表,
header = self.horizontalHeaderItem(column).text()
将“用户名”作为第一列(位置0)和“ ID”为最后一列(位置3)。也
header = self.horizontalHeader().model().headerData(0,Qt.Orientation.Horizontal)
没有任何区别..
有人有什么想法吗?
I have a QTableWidget which I fill with data from SQL - I enabled to reorder the columns in the View by
self.horizontalHeader().setSectionsMovable(True)
To give the user perfect experience, I created much of code, that the user can decide which column he want to see by two list boxed, one showing the headers already in the table visible, in the other, all headers possible by the SQL Table. The user can switch the columns left an right and make them visible or not. The user can also put the elements in the list up and down to reorder the headers from the column. For the visible column list I have to get a list with all visible headers in the TableWidget - But I only have one problem:
When the user drags a Header like "ID" to first position
and I want to get all the headers as a list in a for loop,
header = self.horizontalHeaderItem(column).text()
gives "USERNAME" as first column (position 0) and "ID" as last column (position 3). Also
header = self.horizontalHeader().model().headerData(0,Qt.Orientation.Horizontal)
makes no difference..
Has anybody an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用逻辑索引迭代
you must iterate with logical index