QApplication::mouseButtons 的线程安全和延迟安全如何?
当您从模型获取鼠标信号到插槽中时,传递的参数是 QModelIndex。
QModelIndex 不会告诉您按下了什么按钮。因此,我们可以求助于 QApplication::mouseButtons。但 QApplication::mouseButtons 是当前按钮按下的时间,而不是模型经历点击时的时间。
我的思想实验表明,按下右键后,底层视图将信号发送到我的小部件,但就在我的小部件的插槽收到信号之前,发生了虚假的左键单击。因此,在收到 QModelIndex 时调用 QApplication::mouseButtons 会错误地将单击的行与鼠标左键而不是右键关联起来。这种情况怎么可能发生?
当您查看 Qt 甚至 QML 时,需要大量代码杂技才能在收到 QModelIndex 时获得正确的鼠标按钮信息。这是诺基亚极力宣扬鼠标按钮不可知论的政策吗?
When you get get a mouse signal from a model into your slot, the argument passed is a QModelIndex.
QModelIndex does not tell you what button is pressed. So, we can resort to QApplication::mouseButtons. But QApplication::mouseButtons is the current button press, not when model experienced the click.
My thought experiment is saying that, after the right-button is pressed, the underlying view sends the signal to my widget, but just before my widget's slot received the signal, a spurious left-click occurred. So calling QApplication::mouseButtons on receipt of QModelIndex would wrongly associate the row being click with the left mouse button rather than the right button. How possible is this scenario?
When you look at Qt and even QML, it takes a lot of code acrobatics to achieve proper mouse button info on receipt of a QModelIndex. Is it a policy that nokia is striving to promote mouse button agnosticism?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
I don't think this is a very possible scenario but it may happen.
A "simple" way to be sure about which button was clicked is to subclass
QTableView
(or the view you are using and reimplement themouseReleaseEvent
.By default the
mouseReleaseEvent
emits theclicked
signal if an item of the view is pressedThe trick is to catch the
clicked
signal in your derived class and emit a new signal which except the model index will contain the button as well.You can do something similar with the
mousePressEvent
if you need thepressed
signal as well.