组合框内的 QIcon
我想在 QComboBox 中的条目上包含“删除”图标,但我在捕获鼠标按下事件时遇到问题。我尝试在组合框中捕获它,并且尝试重新实现 QIcon 类以捕获那里的鼠标按下。没有骰子。有人知道该怎么做吗?
-D
I want to include a "remove" icon on entries in my QComboBox, but I am having trouble catching the mouse press event. I've tried to catch it on the combobox, and I've tried reimplemting the QIcon class to catch the mousepress there. No dice. Does anybody know how to do this?
-D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写的代码有点像这样,我想将树视图放在组合框中,并且在单击树上的复选框时需要执行操作。我最终做的是在组合框上安装一个事件过滤器来拦截鼠标单击,找出鼠标单击发生的位置,然后采取行动。也许你可以用你的图标做同样的事情。这是代码:
I've written code a bit like this, where I wanted to put a tree view inside a combo box and I needed to take an action when the check box on the tree was clicked. What I ended up doing was installing an event filter on the combo box to intercept mouse clicks, figure out where the mouse click was happening, and then take an action. Probably you can do the same kind of thing with your icon. Here is the code:
也许您可以重新实现
QComboBox::mousePressEvent(QMouseEvent *e)
并使用ex()
与QComboBox::iconSize()
一起查找是否事件发生在图标上方。如果 Qt 样式决定在组合框中切换标签和图标位置,这将导致中断。不知道这样可以吗?
Maybe you can reimplement
QComboBox::mousePressEvent(QMouseEvent *e)
and usee.x()
together withQComboBox::iconSize()
to find if the event occurred over the icon.This will off cause break if a Qt style decides to switch label and icon position in combo boxes. Don't know if that is possible?