禁用时无法选择 QAbstractItemView 项目
当我将 QAbstractItemModel 的标志设置为可选择但未启用时,我无法通过鼠标单击来选择项目。然而, select() 函数在内部选择对象。 这是qt bug,还是我做错了什么?
When I set flags of QAbstractItemModel selectable but not enabled, I can't select items by mouse click. However internally select() function selects objects.
Is this qt bug, or I do something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我了解,您想要“禁用”该项目,但同时能够选择它。在模型上伪造这一点相当容易。
这会将您的项目显示为灰色,但您仍然可以选择它。
From what I understood, you want to "Disable" the item, but at the same time, be able to select it. it's fairly easy to fake that on the model.
This will paint your item as grayed out, and you will still be able to select it.
你做错了什么。如果您禁用某个小部件,它将显示为灰色,并且不会接收用户鼠标单击和键盘输入。
You're doing something wrong. If you disable a widget it is greyed out and it doesn't receive user mouse clicks and keyboard input.
我刚刚遇到了类似的问题(我需要复制禁用的项目)。这是为禁用项目设置正确样式的解决方案(不忽略任何样式表)。
为您的模型创建自定义项目委托。
将新项目委托设置为您的模型。
I just had similar problem (I need to copy disabled items). Here is solution that sets correct style for disabled items (without ignoring any style sheets).
Create custom item delegate for your model.
Set the new item delegate to your model.