How to set the background of Qimage to transparent?
-
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. -
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. -
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") ) );
@ -
Hi ,
I did what you say but did not get transparent background for the custom curosr
-
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
-
Hi ,
Please anybody knows this issue ..... i am stuck with this
Thanks
-
can you post the cursor image (png file)?
-
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); -
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
-
I just want to set transparent background of cursor. currently it shows black background around the cursor