当值更改时,获取 QTableWidget 中的 QComboBox 的先前值
假设我有一个 QTableWidget,每一行都有一个 QComboBox 和一个 QSpinBox。考虑到我存储它们的值是 QMap
当 comboBoxe
的值或旋转框值发生更改时,我想更新 theMap
。所以我应该知道组合框以前的值是什么,以便替换为组合框的新值,并且还要注意旋转框的值。
我该怎么做?
PS 我决定创建一个插槽,当您单击表格时,它会存储该行组合框的当前值。但这仅在您按下行标题时才有效。在其他地方(点击combobox
或spinbox
)QTableWidget
的itemSelectionChanged()
信号不起作用。
所以一般来说,我的问题是存储所选行的组合框的值,并且我将得到 ComboBox
或 SpinBox
甚至更改,并将处理 theMap< /代码> 很容易。
Say I have a QTableWidget
and in each row there is a QComboBox
and a QSpinBox
. Consider that I store their values is a QMap<QString /*Combo box val*/,int /*spin box val*/> theMap;
When comboBoxe
s value or spin boxes value is being changed I want to update theMap
. So I should know what was the former value of the combo box in order to replace with the new value of the comboBox
and also take care of the value of the spin box.
How can I do this?
P.S. I have decided to create a slot that when you click on a table, it stores the current value of the combo box of that row. But this works only when you press on row caption. In other places (clicking on a combobox
or on a spinbox
) itemSelectionChanged()
signal of QTableWidget
does not work.
So in general my problem is to store the value of the combo box of selected row, and the I will get ComboBox
or SpinBox
change even and will process theMap
easily.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何创建您自己的派生 QComboBox 类,大致如下:
然后只需连接到 myTextChangedSignal 即可,该类现在另外提供旧的组合框文本。
我希望这有帮助。
How about creating your own, derived QComboBox class, something along the lines of:
And then just connect to
myTextChangedSignal
instead, which now additionally provides the old combo box text.I hope that helps.
有点晚了,但我遇到了同样的问题并以这种方式解决:
A bit late but I had the same problem and solved in this way:
我的建议是实现一个模型,这将帮助您在数据和编辑数据的 UI 之间进行清晰的分离。然后,您的模型将收到给定模型索引(行和列)更改为新数据的通知,并且您可以更改此时所需的任何其他数据。
My suggestion is to implement a model, which would help you make a clean separation between the data, and the UI editing the data. Your model would then get notified that a given model index (row and column) changed to the new data, and you could change whatever other data you needed to at that point.
我只是遇到了类似的问题,但对我来说,我需要以前的索引来处理一些非常琐碎的事情,因此定义和实现整个类是不合理的。
所以我所做的就是保留一个名为“previousIndex”的参数,并仅在我完成所需的所有操作后才更新它的值
I was just having a similar issue, but for me i needed the previous index for something very trivial so defining and implementing a whole class for it was unjustified.
So what I did instead was keep an argument called say 'previousIndex' and updated it's value only after I had done everything I needed with it