I am a newcomer to using Python and Qt and the main problem that I have
is the dearth of any example code or books describing the use of Python
and Qt together.
My current problem is that I want to create a custom cursor, from my
understanding of it I need to create two "QBitmap"s, one of which will
be the mask and then using these to create a "QCursor".
I don't mine whether the "QBitmap"s are hardcoded in the source code or
come from image files, just as long as I can create a new cursor:
I have searched all the available code sources I can find:
www.koders.com
Eric
Veus
Civil
Qomics
for examples of how to create cursors but to no avail. So if amyone can
tell me what I'm doing wrong, it would be much appreciated, here's my
code:
#
# InlineBitmapCur sor.py
# environment: Mac OS X 10.4.2 - Python 2.4.1 - Qt 3.3.5
# status: does not produce any error messages but also does not
change
# the cursor.
# standalone file
import sys, os
from qt import *
class MainWindow(QMai nWindow):
def __init__(self, *args):
QMainWindow.__i nit__(self, *args)
self.setCaption ("Custom Cursor")
self.grid=QGrid (2, self)
self.setCentral Widget(self.gri d)
self.grid.setFr ameShape(QFrame .StyledPanel)
self.button1=QP ushButton("Arro w Cursor", self.grid)
self.button2=QP ushButton("Bitm ap Cursor", self.grid)
self.arrowCurso r = QCursor(Qt.Arro wCursor)
self.setCursor( self.arrowCurso r)
self.connect(se lf.button1, SIGNAL("clicked ()"), self.arrow)
self.connect(se lf.button2, SIGNAL("clicked ()"), self.bitmap)
# 8 * 8 bitmap - two random bit maps
# self.bitmap2 = QBitmap(8, 8,
"\x89\x50\x4e\x 47\x0d\x0a\x1a\ x0a")
self.bitmap2 = QBitmap(8, 8,
"\x89\x55\x55\x 55\x0d\x0a\x1a\ x0a")
self.bitmap3 = QBitmap(8, 8,
"\x88\x67\x34\x aa\x23\x60\x84\ xbb")
print "bitmap2 " + repr(self.bitma p2)
print "bitmap3 " + repr(self.bitma p3)
self.inlineBitm apCursor = QCursor(self.bi tmap2, self.bitmap3)
print "before setCursor"
self.setCursor( self.inlineBitm apCursor)
print "after setCursor"
def arrow(self):
self.setCursor( self.arrowCurso r)
def bitmap(self):
self.setCursor( self.inlineBitm apCursor)
def main(args):
app=QApplicatio n(args)
win=MainWindow( )
win.show()
app.connect(app , SIGNAL("lastWin dowClosed()"), app, SLOT("quit()")
)
app.exec_loop()
if __name__=="__ma in__":
main(sys.argv)
This is what happen when it executes:
[~] steve% "/usr/local/bin/pythonw"
"/Users/steve/PythonDev/qt3.3.5/CursorExamples/InlineBitmapCur sor.py"
&& echo Exit status: $? && exit 1
bitmap2 <qt.QBitmap object at 0x80b30>
bitmap3 <qt.QBitmap object at 0x80b70>
before setCursor
after setCursor
thanks,
Steve Greenwood