473,749 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
#
# 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

Dec 2 '05 #1
2 5774
On Friday 02 December 2005 3:31 pm, St****@gmail.co m 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(Tr ue)" but this does not have the
desired effect.

def bitmap(self):
self.setCursor( self.inlineBitm apCursor)
self.repaint(Tr ue)
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
1242
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
6528
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 bar AND a toolbar, BOTH types of command bars for this form. But in the PROPERTIES of this form it doesn't allow but one at the time apparently. Anyway around this?
2
30162
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.) and would like to make the dialog look and act like the standard MessageBox. Therefore, I would like to put in the message section the same type of icons found in the MessageBox dialog, such as MessageBoxIcon.Exclamation. In another post here I had...
0
1635
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. At one place collection of controls representing objects is present. User should be able to click on respective control that time cursor should change. And whenever mouse comes in this control area locations where control can be placed should get...
1
1469
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). can you tell me where can i find information about create custom control? Thanks. Pablo Salazar ( sorry by my English).
2
9419
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 Concern, Homa Wong
6
3563
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 error page. All six steps in the article work just fine. Then at the end of the article, there is a little comment about redirecting errors to an aspx page (instead of an html page):
0
1258
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 on this, how do start my work . Either create client side table using javascript or Server side table using Gridview or Server Table. If anyone have same experience on this, Please suggest me how do approach.
2
5223
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 is a brain freeze, but what could I possibly be missing? WtS
0
8997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.