I have a QPushButton with an image that has two areas that I want to handle differently when clicked. Due to the positioning on the image, I cannot really use separate buttons for the two images.
What I’d like to do is, in the slot where I am handling the click, have it check the coordinates of the click to determine which area was clicked.
Is there a way to access this?
This is what first comes to mind. It should work, although there may be a simpler way:
QPushButton.mousePressEventandmouseReleaseEvent) and, before calling the base class implementation, set a property in your object usingsetPropertywith the position of the mouse click. (The position is available from the event parameter.)sender()to get the button, and read the property usingproperty().If you don’t need to treat your object as the base class (
QPushButton*) you could just create a new signal that includes the mouse event and attach that to your slot. Then you wouldn’t need the property at all.