Changing cursor shape to haircross

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
vitort
Posts: 12
Joined: Tue Feb 04, 2014 5:59 pm

Changing cursor shape to haircross

Post by vitort »

Hi
I'm trying to create a tool that when the user graphically inputs points the cursor changes to a haircross shape so...if I try in FreeCAD's python console:

from PySide import QtCore, QtGui
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))

on:
OS: Windows XP
Platform: 32-bit
Version: 0.14.3389
Python version: 2.6.2
Qt version: 4.5.2
Coin version: 3.1.0
SoQt version: 1.4.1
OCC version: 6.5.1

I get a nice haircross cursor shape... but if I try

on;
OS: Ubuntu 13.10
Platform: 32-bit
Version: 0.14.3559 (Git)
Branch: master
Hash: 1fffc978b4c2873da5826c1de12207f3b292c4cf
Python version: 2.7.5+
Qt version: 4.8.4
Coin version: 4.0.0a
SoQt version: 1.5.0
OCC version: 6.7.0

I get nothing.

What do you think could be wrong?
I want it to work both on Windows and Ubuntu (Lubuntu actually) because I use both OS's depending on where I am working.

Should I not use PySide for this?
Really apreciated your inputs

Vitor T
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Changing cursor shape to haircross

Post by wmayer »

What do you think could be wrong?
Hard to say. Does any other cursor type like WaitCursor, ForbiddenCursor, BusyCursor, ... work?
Should I not use PySide for this?
This has nothing to do with PySide. It's just a Python wrapper and the actual stuff happens inside Qt.
vitort
Posts: 12
Joined: Tue Feb 04, 2014 5:59 pm

Re: Changing cursor shape to haircross

Post by vitort »

Hard to say. Does any other cursor type like WaitCursor, ForbiddenCursor, BusyCursor, ... work?
Hi wmayer

I've tried all but none work.
I've tried something stupid say "StupidCursor" and python says:
' Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: type object 'PySide.QtCore.Qt' has no attribute 'StupidCursor'

If I change "from PySide import ..." to "from PyQt4 import ..." they all work except, obviously, the "StupidCursor" that gives:
' Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: type object 'Qt' has no attribute 'StupidCursor'

I'm not familiar with wrappers and how they work I'm just trying the FreeCAD API so I can't help much here except experimenting and share results.
For now I'll stick to PyQt4.
I'll keep trying PySide in the next releases and see if it works.

Vitor T
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Changing cursor shape to haircross

Post by wmayer »

Oh, interesting. Then maybe there is indeed something wrong with PySide.

What does this give you?

Code: Select all

from PySide import QtCore, QtGui
int(QtCore.Qt.CrossCursor)
The expected value must be 2.

If this is not 2 (then it's of course a bug in Pyside) and you could try this:

Code: Select all

from PySide import QtCore, QtGui
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CursorShape(2)))
vitort
Posts: 12
Joined: Tue Feb 04, 2014 5:59 pm

Re: Changing cursor shape to haircross

Post by vitort »

Hello wmayer
What does this give you?

Code: Select all

from PySide import QtCore, QtGui
int(QtCore.Qt.CrossCursor)
Well this gives me 2 as you say.
If this is not 2 (then it's of course a bug in Pyside) and you could try this:

Code: Select all

from PySide import QtCore, QtGui
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CursorShape(2)))
This gives me nothing, no error message, nothing. The cursor remains arrow, just like previously with 'QtCore.Qt.CrossCursor' .
Using the same code with PyQt4, then I get the the cross cursor.
Hope this helps.

Using the Draft module toolbar (line, DraftWire, circle, etc,...) the Cross Cursor shows up and that's the kind of thing I'm after. I haven't figured out how Yorik did it (node, child ??).

Cheers
Vitor T
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Changing cursor shape to haircross

Post by yorik »

vitort wrote:Using the Draft module toolbar (line, DraftWire, circle, etc,...) the Cross Cursor shows up and that's the kind of thing I'm after. I haven't figured out how Yorik did it (node, child ??).
Look in DraftSnap.py, at the setCursor() function... But I use a custom image there, not the default Qt cross, maybe that's the problem.
vitort
Posts: 12
Joined: Tue Feb 04, 2014 5:59 pm

Re: Changing cursor shape to haircross

Post by vitort »

I'll look in DraftSnap.py and see if I can reproduce somehow in my script.

Thanks Yorik and Wmayer
Post Reply