473,408 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do you create a custom QCursor in Python Qt?

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:
#
# InlineBitmapCursor.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(QMainWindow):

def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.setCaption("Custom Cursor")
self.grid=QGrid(2, self)
self.setCentralWidget(self.grid)

self.grid.setFrameShape(QFrame.StyledPanel)

self.button1=QPushButton("Arrow Cursor", self.grid)

self.button2=QPushButton("Bitmap Cursor", self.grid)

self.arrowCursor = QCursor(Qt.ArrowCursor)
self.setCursor(self.arrowCursor)

self.connect(self.button1, SIGNAL("clicked()"), self.arrow)
self.connect(self.button2, SIGNAL("clicked()"), self.bitmap)

# 8 * 8 bitmap - two random bit maps
# self.bitmap2 = QBitmap(8, 8,
"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")
self.bitmap2 = QBitmap(8, 8,
"\x89\x55\x55\x55\x0d\x0a\x1a\x0a")
self.bitmap3 = QBitmap(8, 8,
"\x88\x67\x34\xaa\x23\x60\x84\xbb")
print "bitmap2 " + repr(self.bitmap2)
print "bitmap3 " + repr(self.bitmap3)

self.inlineBitmapCursor = QCursor(self.bitmap2, self.bitmap3)
print "before setCursor"
self.setCursor(self.inlineBitmapCursor)
print "after setCursor"

def arrow(self):
self.setCursor(self.arrowCursor)
def bitmap(self):
self.setCursor(self.inlineBitmapCursor)
def main(args):
app=QApplication(args)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")
)
app.exec_loop()
if __name__=="__main__":
main(sys.argv)


This is what happen when it executes:

[~] steve% "/usr/local/bin/pythonw"
"/Users/steve/PythonDev/qt3.3.5/CursorExamples/InlineBitmapCursor.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

Dec 2 '05 #1
2 5735
On Friday 02 December 2005 3:31 pm, St****@gmail.com wrote:
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:


How about looking at the cursor.py example that comes with PyQt? It
demonstrates the standard cursors and implements a custom cursor.

Phil
Dec 2 '05 #2
Thanks Phil,

Good idea, I had failed to notice these code examples and been
struggling the "qt3" examples from pyqtsrc.tgz for months.

So, I found my mistake, I was using a 8*8 bitmap, I have now corrected
it and use a 16*16 bitmap (which is the standard size on Mac OS X) read
in from a "PNG" file created in Photoshop in bitmap mode and it works
just great.

I failed to read the C++ documentation for Qt closely enough where it
states:

Valid cursor sizes depend on the display hardware (or the underlying
window system). We recommend using 32x32 cursors, because this size is
supported on all platforms. Some platforms also support 16x16, 48x48
and 64x64 cursors.

As a Python novice I had simply taken the bitmap that was available in
the documentation for Qbitmap, which happens to be an 8*8 bitmap.
Interestingly on my G5 iMac Mac OS X 10.4.3 running Python 2.4.1 &
Qt3.3.5 QCursors of both 16*16 & 32*32 works perfectly; whereas on my
G4 Powerbook Mac OS X 10.4.2 running the same Python 2.4.1 & Qt3.3.5, a
16*16 QCursor works but a 32*32 QCursor doesn't, but since there are no
error messages that is all that I can report. Interesting!

I have also tested my code on a PC, which supports 32*32 but does not
support
16*16.

-------------------

I have two auxiliary questions if anybody can help me.

1: When I click on a button the cursor does not change immediately, the
cursor only actually gets re-drawn when I physically move the mouse.
Is there a way to get it to update instantaneously?
After "setCursor() I call "repaint(True)" but this does not have the
desired effect.

def bitmap(self):
self.setCursor(self.inlineBitmapCursor)
self.repaint(True)
2: The cursor that I want to customise is the wait cursor; under Mac OS
X this is an animated cursor displaying a wristwatch with hands that go
around?
So my question is where do I find the code that produces this effect,
is it written in C++ or Python and how can I imitate it?

Steve

Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jai | last post by:
Dear All How to create Custom Controls in ASP.Net,Can u Please Help Me out in this context.
2
by: Larry R Harrison Jr | last post by:
I have Access 97. I know how to create custom command bars. I typically create pull-down menus; seldom do I create toolbars. But I have a case where I would; in fact, I would like to have a menu...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
0
by: Shailaja Kulkarni | last post by:
Hi All, I am new to component development. I want to create custom control to arrange contained controls in form of polygonal shape. The objects are placed in separate panel on the some form....
1
by: Pablo Salazar | last post by:
Hi People. Somebody can help me. Some time ago I began to develop database project for a college. Actually control don't adjust that I need. I need to create a control from beginning ( from 0)....
2
by: Homa | last post by:
Hi all, Does any one know how to create a custom window like the control panel of PowerDVD and WinAmp in C#? If I need to use C++ Library to do this, where should I head to? Thanks for...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
0
by: th12345 | last post by:
Hi All, I want to create custom excel sheet page in my web application like how Google spreadsheet was created. I do not want load data into Microsoft excel sheet. Please give some idea...
2
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have an existing (WPF) Class Library project that I'd like to add a WPF Custom Control to. However, when I try to Add New Item, that isn't one of the available options. Perhaps this...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.