How to set the background of Qimage to transparent?
-
wrote on 2 Dec 2013, 08:30 last edited by
Hi,
i am new to Qt programming. i have created the Qimage object by providing image[.png] file.
ex.
Qimage image("some.png").i am using qt 4.8
please help me to set transparent background of image. currently it shows black background.
Thank You
-
you can try to convert the QImage:
@
image = image.convertToFormat(QImage::Format_ARGB32);
@
Assuming the PNG file really has a alpha channel set. -
wrote on 2 Dec 2013, 10:13 last edited by
Hi,
i checked the format and it has Format_ARGB32. also i have checked the alpha set by using hasAlphaChannel () Api and it returns true. -
wrote on 2 Dec 2013, 11:28 last edited by
Hi ,
one more thing i forgot to tell u that i am generating custom Qcursor from the image.
Ex
Qimage image(“some.png”).
QBitmap(image.size());QCurosr(image,mask,hot_spot_x,hot_spot_y);
-
so why don't you just use QPixmap directly?
@
widget->setCursor( QCursor( QPixmap("image.png") ) );
@ -
wrote on 2 Dec 2013, 12:46 last edited by
Hi ,
I did what you say but did not get transparent background for the custom curosr
-
wrote on 2 Dec 2013, 14:43 last edited by
Hi ,
actually i am converting my application from 3.0 to 4.8. the code for custom cursor is already implemented. it works fine it qt 3.0. cursor has transparent background when it works in qt 3.0. but when i test same code in qt 4.8 it shows black background.
Ex code snippet.
Qimage image
Qimage image1(image.size(),1,2,Qimage::BigEndian);
Qimage image1_mask(image.size(),1,2,Qimage::BigEndian);
int hot_x=-1;
int hot_y=-1setPixel according to height and width of Qimage object.
QBitmap bit(image1.size())
Qbitmap bt_map(image1_mask.size())new Qcursor(bt,bt_map,hot_x,hot_y);
is anything wrong here. please help me i have tried several combination for this
Thank You
-
wrote on 3 Dec 2013, 11:26 last edited by
Hi ,
Please anybody knows this issue ..... i am stuck with this
Thanks
-
can you post the cursor image (png file)?
-
wrote on 5 Dec 2013, 12:52 last edited by
Hello yhodage,
Try this combination...[Qt 4.8]
If You have transparent cursor image then it would be good ,other wise make cursor png to transparent.
QPixmap map("some.png");
QCursor mCursor(map);
setCursor(mCursor); -
wrote on 23 Dec 2013, 13:32 last edited by
Hi ,
i had tried that one but no result. actually a black box appears around the custom cursor. the image that is used in custom cursor is not transparent but with the code snippet that i had paste earlier works with not transparent image in qt 3.0. i just port my application to qt 4.8 and the problem starts here.
please help me to resolve this issue.
Thanks
-
wrote on 23 Dec 2013, 13:53 last edited by
I just want to set transparent background of cursor. currently it shows black background around the cursor