Cursor corruption with pyqt4 and a work-around.

I have been developing an application using PyQt ant Matplotlib and encountered
a problem with the mouse cursor shape being incorrect. I found a work-around
that seems to work, but I think this is a bug and the fix needs to go into the
Matplotlib code base. Here are details.

My application has a central widget used fo r a Matplotlib Figure.
Additionally there is a menu bar, button bar and two dock panels with
controls for the plot. I see the following behavior for the cursor:

* On start up, the cursor acts normally on startup provided
  the mouse cursor is not inside the figure widget on start-up.

* Mouse pointer shapes are set by Windows (in this case VISTA)
  and change shape according to location. For example, touching
  the application window's border results in the arrow pointer
  changing shape to a double-headed arrow indicating the border
  can be dragged to adjust the size of the window.

* Once the mouse pointer touches the Matplotlib figure widget
  in any way, the mouse pointer will cease to show the double-arrow
  shape on the window borders - the pointer remains an arrowhead.
  You can still resize the window and the cursor does change to
  a double-arrow when you press the left button.

My workaround for this was to add the following lines of code in my
application:

        def onleave(self):
           QtGui.QApplication.restoreOverrideCursor()

        self.fig.canvas.mpl_connect('figure_leave_event', onleave)

I guessed these lines by studying the matplotlib code. Probably they
need to go somewhere inside the Matplotlib class definitions.

I hope this helps developers to correct this problem. My application
code is medium-large and I didn't try to build a smaller example. The
mysterious 3-line workaround solves my problem for the moment.
Perhaps it will help another PyQt and Matplotlib user and perhaps
urge developers to fix the problem in the Matplotlib core.

David Smith

Thanks Mr.David,

I too developing an application using PyQt and Matplotlib. Though I may not use cursor for my application, It will keeps me the aware of the things.

With Thanks
Sathishkumar

···

On Fri, Jun 18, 2010 at 8:34 AM, David Smith <davidhsmith255@…287…> wrote:

I have been developing an application using PyQt ant Matplotlib and encountered

a problem with the mouse cursor shape being incorrect. I found a work-around

that seems to work, but I think this is a bug and the fix needs to go into the

Matplotlib code base. Here are details.

My application has a central widget used fo r a Matplotlib Figure.

Additionally there is a menu bar, button bar and two dock panels with

controls for the plot. I see the following behavior for the cursor:

  • On start up, the cursor acts normally on startup provided

    the mouse cursor is not inside the figure widget on start-up.

  • Mouse pointer shapes are set by Windows (in this case VISTA)

    and change shape according to location. For example, touching

    the application window’s border results in the arrow pointer

    changing shape to a double-headed arrow indicating the border

    can be dragged to adjust the size of the window.

  • Once the mouse pointer touches the Matplotlib figure widget

    in any way, the mouse pointer will cease to show the double-arrow

    shape on the window borders - the pointer remains an arrowhead.

    You can still resize the window and the cursor does change to

    a double-arrow when you press the left button.

My workaround for this was to add the following lines of code in my

application:

    def onleave(self):

       QtGui.QApplication.restoreOverrideCursor()



    self.fig.canvas.mpl_connect('figure_leave_event',  onleave)

I guessed these lines by studying the matplotlib code. Probably they

need to go somewhere inside the Matplotlib class definitions.

I hope this helps developers to correct this problem. My application

code is medium-large and I didn’t try to build a smaller example. The

mysterious 3-line workaround solves my problem for the moment.

Perhaps it will help another PyQt and Matplotlib user and perhaps

urge developers to fix the problem in the Matplotlib core.

David Smith


ThinkGeek and WIRED’s GeekDad team up for the Ultimate

GeekDad Father’s Day Giveaway. ONE MASSIVE PRIZE to the

lucky parental unit. See the prize list and enter to win:

http://p.sf.net/sfu/thinkgeek-promo


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Now that you mention it, I have seen similar behavior. Thanks for the
report, I'll look into it.

Darren

···

On Thu, Jun 17, 2010 at 11:04 PM, David Smith <davidhsmith255@...287...> wrote:

I have been developing an application using PyQt ant Matplotlib and encountered
a problem with the mouse cursor shape being incorrect. I found a work-around
that seems to work, but I think this is a bug and the fix needs to go into the
Matplotlib code base. Here are details.

My application has a central widget used fo r a Matplotlib Figure.
Additionally there is a menu bar, button bar and two dock panels with
controls for the plot. I see the following behavior for the cursor:

* On start up, the cursor acts normally on startup provided
the mouse cursor is not inside the figure widget on start-up.

* Mouse pointer shapes are set by Windows (in this case VISTA)
and change shape according to location. For example, touching
the application window's border results in the arrow pointer
changing shape to a double-headed arrow indicating the border
can be dragged to adjust the size of the window.

* Once the mouse pointer touches the Matplotlib figure widget
in any way, the mouse pointer will cease to show the double-arrow
shape on the window borders - the pointer remains an arrowhead.
You can still resize the window and the cursor does change to
a double-arrow when you press the left button.

My workaround for this was to add the following lines of code in my
application:

   def onleave\(self\):
      QtGui\.QApplication\.restoreOverrideCursor\(\)

   self\.fig\.canvas\.mpl\_connect\(&#39;figure\_leave\_event&#39;,  onleave\)

I guessed these lines by studying the matplotlib code. Probably they
need to go somewhere inside the Matplotlib class definitions.

I hope this helps developers to correct this problem. My application
code is medium-large and I didn't try to build a smaller example. The
mysterious 3-line workaround solves my problem for the moment.
Perhaps it will help another PyQt and Matplotlib user and perhaps
urge developers to fix the problem in the Matplotlib core.

I think this has been fixed in svn, on both the maintenance branch and
the trunk.

···

On Fri, Jun 18, 2010 at 7:50 AM, Darren Dale <dsdale24@...287...> wrote:

On Thu, Jun 17, 2010 at 11:04 PM, David Smith <davidhsmith255@...287...> wrote:

I have been developing an application using PyQt ant Matplotlib and encountered
a problem with the mouse cursor shape being incorrect. I found a work-around
that seems to work, but I think this is a bug and the fix needs to go into the
Matplotlib code base. Here are details.

My application has a central widget used fo r a Matplotlib Figure.
Additionally there is a menu bar, button bar and two dock panels with
controls for the plot. I see the following behavior for the cursor:

* On start up, the cursor acts normally on startup provided
the mouse cursor is not inside the figure widget on start-up.

* Mouse pointer shapes are set by Windows (in this case VISTA)
and change shape according to location. For example, touching
the application window's border results in the arrow pointer
changing shape to a double-headed arrow indicating the border
can be dragged to adjust the size of the window.

* Once the mouse pointer touches the Matplotlib figure widget
in any way, the mouse pointer will cease to show the double-arrow
shape on the window borders - the pointer remains an arrowhead.
You can still resize the window and the cursor does change to
a double-arrow when you press the left button.

My workaround for this was to add the following lines of code in my
application:

   def onleave\(self\):
      QtGui\.QApplication\.restoreOverrideCursor\(\)

   self\.fig\.canvas\.mpl\_connect\(&#39;figure\_leave\_event&#39;,  onleave\)

I guessed these lines by studying the matplotlib code. Probably they
need to go somewhere inside the Matplotlib class definitions.

I hope this helps developers to correct this problem. My application
code is medium-large and I didn't try to build a smaller example. The
mysterious 3-line workaround solves my problem for the moment.
Perhaps it will help another PyQt and Matplotlib user and perhaps
urge developers to fix the problem in the Matplotlib core.

Now that you mention it, I have seen similar behavior. Thanks for the
report, I'll look into it.