PDA

View Full Version : Does QDrag support QBitmap?



alfa_wu
3rd May 2007, 02:48
I wanted to drawing a mono color cursor when mouse start to drag.
But it seems that only support QPixmap format(ARGB color, not mono color).

Do we have method to draw mono color cursor when we start dragging ?

wysota
3rd May 2007, 15:39
Can we see the code? QBitmap inherits QPixmap so everything that's possible using QPixmap should be doable using QBitmap.

alfa_wu
4th May 2007, 06:44
You can reproduce it by modify exmaple ~qt4.x.src/examples/draganddrop/draggableicons/dragwidget.cpp
Replace Line #110 ( drag->setPixmap(pixmap); ) with


Qt Code:
static unsigned char drag_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x41, 0x00, 0x00, 0x41, 0x00, 0xff, 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x0f, 0x40, 0x10, 0x00, 0x40, 0x10, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
QBitmap pixmap = QBitmap::fromData( QSize(20, 20), drag_bits, QImage::Format_Mono);
pixmap.setMask(QPixmap::grabWidget(this).createHeu risticMask(true));
drag->setPixmap((QPixmap)pixmap);

The cusor will be color, not mono

wysota
4th May 2007, 08:20
Works quite fine for me. I just replaced the construction and serialisation of the pixmap from the example with your pixmap.

alfa_wu
7th May 2007, 02:23
It did not work in my enviornment.
When I pressed some widget and try to move, you can find that cursor's background is wrong.
That is, the cursor must be mono, not color.

wysota
7th May 2007, 09:15
What exactly did you do? Did you replace all occurences of the color pixmap in code with the bitmap?

alfa_wu
8th May 2007, 08:41
I only replaced Line #110 ( drag->setPixmap(pixmap); ) with my code


{
static unsigned char drag_bits[] = { ...};
QBitmap pixmap = QBitmap::fromData( QSize(20, 20), drag_bits, QImage::Format_Mono);
pixmap.setMask(QPixmap::grabWidget(this).createHeu risticMask(true));
drag->setPixmap((QPixmap)pixmap);
}

wysota
8th May 2007, 10:59
As I said, you have to replace the construction and serialisation code of the pixmap. Otherwise your pixmap won't be used at all (the code I mentioned is around line #100 or earlier).

alfa_wu
9th May 2007, 02:56
I am sorry that I can not deliver my question clearly.
I attached drag.jpg file, and I wanted the cursor in the picture is mono-color.
I do not wanted to change all content of pixmap.

I only wanted to show mono-color mouse when dragging.
That is, I wanted to set mono-color in function "drag->setPixmap()".

Thanks your reply.:)