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?
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
mouseReleaseEventemits theclickedsignal if an item of the view is pressedThe trick is to catch the
clickedsignal 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
mousePressEventif you need thepressedsignal as well.