使用 PyQT,如何过滤具有自定义列表的 QComboBox 的 mousePressEvent
我有一个带有自定义列表对象的 QComboBox。
自定义列表对象具有自定义 mousePressEvent
,以便当用户单击其中之一时带有 +/-(扭曲)的圆圈,列表会展开/折叠。
当我将列表与组合框一起使用时,当用户单击扭曲时,列表会展开/折叠,但选择会更改,并且列表会隐藏。 我如何过滤它,以便当用户单击扭曲时,选择不会更改,并且列表不会隐藏。
其他屏幕截图
所有节点都崩溃了:
列表隐藏:
I've got a QComboBox
with a custom list object.
The custom list object has a custom mousePressEvent
so that when the user click on one of the circles with a +/- (a twisty), the list is expanded/collapsed.
When I use the list with the combo box, when the user clicks on a twisty, the list is expanded/collapsed, but the selection is changed, and the list is hidden. How can I filter this so that when the user click on a twisty, the selection is not changed, and the list not hidden.
Additional screenshots
All of the nodes collapsed:
List hidden:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QT 有一个“捕获”
QEvent.MouseButtonRelease
的eventFilter
。 因此,我所做的就是安装我自己的eventFilter
,如果用户单击节点,它会过滤QEvent.MouseButtonRelease
事件。在我的列表对象中,我有以下方法:
mousePressEvent
在mouseReleaseEvent
之前运行。然后在自定义组合框中,我过滤事件:
QT has a
eventFilter
that "captures"QEvent.MouseButtonRelease
. So what I have done is installed my owneventFilter
that filtersQEvent.MouseButtonRelease
events if the user click on a node.In my list object I have the following method:
The
mousePressEvent
runs beforemouseReleaseEvent
.Then in the custom combobox, I filter the event:
在我的脑海中,您可以子类
QComboBox
并覆盖hideEvent(QHideEvent)
(继承自QWidget
)您的屏幕截图看起来像是一个有趣的用途组合框,我很好奇为什么你没有使用
TreeView
样式控件而不是列表?编辑(2009年3月14日):
我查看了Qt源代码,看起来当捕获键盘和鼠标事件时,一旦qt决定发出
“activated( int index)"
信号,"hidePopup()"
已被调用。因此,除了重写事件过滤器代码之外,另一个选择是将
"activated(int index)"
或"highlighted(int index)"
信号连接到一个插槽,该插槽可以调用"showPopup()"
这将重新引发列表项。 如果您遇到令人讨厌的消失/出现绘画问题,您可能必须让 Qt 在弹出窗口可见时延迟绘画事件。希望有帮助!
Off the top of my head, you could subclass
QComboBox
and overridehideEvent(QHideEvent)
(inherited fromQWidget
)Your screenshot looks like an interesting use of a combo box, I'm curious as to why you haven't used a
TreeView
style control instead of a list?Edit (Mar 14 2009):
I looked at the Qt source code and it looks like when the keyboard and mouse events are captured, that as soon as qt has decided to emit the
"activated(int index)"
signal,"hidePopup()"
has been called.So apart from rewriting their event filter code, another option is to connect the
"activated(int index)"
or"highlighted(int index)"
signal to a slot that can call"showPopup()"
which would re-raise the list items. If you get a nasty disappear/appear paint issue you may have to get Qt to delay the paint events while the popup is visible.Hope that helps!