Personal computing discussed

Moderators: SecretSquirrel, just brew it!

Crayon Shin Chan
Minister of Gerbil Affairs
Topic Author
Posts: 2299
Joined: Fri Sep 06, 2002 11:14 am
Location: Malaysia

Drawing a cursor on an image in Qt

Sat Nov 19, 2011 12:23 pm

As far as I know, to display an image in Qt 3.3 requires the following steps:
1. load from image file into QImage using Qt functions
2. create a QPixmap object, use its functions to convert loaded image into the pixmap
3. create a QLabel, point it to converted pixmap
4. tell the QLabel to update()

Now I want to have a cursor on top of the image, that shows a human's current position in relation to the image (and the shapes depicted within the image) through a nice white moving + cursor, or something of the sort. But how do I do that? The only way you can change the image significantly to redraw the position of the cursor every time the user's position updates is to manipulate the QImage before it gets converted into a QPixmap. Which Qt discourages because supposedly converting from QImage to QPixmap is slow, and shouldn't be done for things that need to be updated often. Unfortunately they don't discuss any alternatives.

Or, if there was a way to draw on top of the existing QLabel, for instance, have another QLabel on top of the existing QLabel that displays the image... but I don't think that's allowed in Qt. I've heard about clipping masks, but they don't seem to be flexible enough, they block out a simple circular area where the cursor is, so you can't see anything near where you are, and the worst thing is it blocks out the area with black, which is also in my images. And I don't know how to change the colour. Plus to make any shape more complex than a circle, you have to xor multiple QRegions each time the cursor's position changes - and that can't be an efficient way of doing anything.

How would you guys do this? And no I will not upgrade to Qt4 or VS2008. I wouldn't get credit or cash for such a monumental task anyway.
Mothership: Thuban 1055T@3.7GHz, 12GB DDR3, M5A99X EVO, GTX470+Icy Vision Rev.2@840/3800, Vertex 2E 60GB
Supply ship: Sargas@2.8GHz, 12GB DDR3, M4A88TD-V EVO/USB3
Corsair: Macbook Air Ivy Bridge

Who is online

Users browsing this forum: No registered users and 1 guest