8

I am interested in creating a custom mouse cursor, so that during drag and pick events on certain lines or points, the mouse changes from an arrow to a hand (or other symbol).

What is the best method of doing this?

I assume this is possible since the mouse cursor changes to a small cross hair during zoom operations. If possible, a solution using the PyQt/PySide backend would be preferable.

1 Answer 1

4

What you need is mpl_canvas. Follow this tutorial to set one up.

With an mpl_canvas, you can then set up events that get triggered.

fig = matplotlib.figure.Figure()
cid = fig.canvas.mpl_connect('button_press_event', your_method)

There are several kinds of signals under here (listed under Events).

With your signal set up, your_method gets called, with an event parameter. So do something like:

def your_method(event):
    print('Your x and y mouse positions are ', event.xdata, event.ydata)

Click on the corrosponding Class and description links to see what exactly is in event. for a specific mpl_canvas Event.

In your specific case, to change how the mouse looks your_method should look something like:

 def your_method(event):
     #changes cursor to +
     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.