PyQT 组合框仅对用户交互做出反应

发布于 2024-07-17 17:19:46 字数 404 浏览 6 评论 0原文

我有一个列表框,您可以在其中选择用户。其左侧是一个组合框,列出了用户可以放入的可用组。 如果用户在一个组中,组合框将自动设置为该组。 我想做到这一点,以便当您更改组选择时,它会将用户移动到该组。 我添加了这个连接:

QtCore.QObject.connect(self.GroupsBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.HandleGrouping)

问题是,由于我将在不同的组中选择不同的用户,因此每次选择新用户时,组合框中的默认选项都会发生变化,并且 Qt 会将其注册为“currentIndexChanged”信号。

似乎没有办法仅在用户与小部件本身直接交互时触发信号。 我可以使用什么方法来解决这个问题?

I have a listbox that you can select users in. To the left of that is a combobox listing the available groups the user can be put it. If the user is in a group, the combobox will automatically be set to that group. I want to make it so when you change the group selection, it will move the user to that group. I added this connection:

QtCore.QObject.connect(self.GroupsBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.HandleGrouping)

The problem is that since I'll be selecting different users in different groups, every time I select a new user, the default option in the combobox changes and Qt registers this as a 'currentIndexChanged' signal.

There appears to be no way to only fire the signal on direct user-interaction with the widget itself. What methods can I use to work around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2024-07-24 17:19:46

捕获来自 QComboBox 的信号 (activated(int index)),并据此更新所选用户。 在您的处理函数中,如果组合框中选定的索引与选定用户所在的组相同,则不要执行任何操作。

也许将组合框移动到用户列表框的右侧,因为您的操作顺序将是“选择用户” --> 选择组。

Catch a signal from the QComboBox (activated(int index)), and update the selected user based on that. In you Handler function, don't do anything if the selected index in the combobox is the same as the group the selected user is in.

Maybe move your combobox to the right of the user listbox, as your order of actions will be Select User --> Select Group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文