PDA

View Full Version : Drag'n'Drop pixmap issue



azsde
28th April 2015, 15:14
Hello,

I'm currently trying to implement a drag'n'drop feature in a small program I'm developing.

The feature is partially working, the item can be dragged from a widget to another, but as the drag begin, the QPixmap associated with it is completely black.

Here's exactly what happens :

11144

And here's the code where I start the drag event :



void ActionButtonWidget::mouseMoveEvent(QMouseEvent * event)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << * this;
mimeData->setData("customWidget/actionButton",itemData);
drag->setMimeData(mimeData);
drag->setPixmap(QPixmap(*(this->pixmap()))); //This should be getting the pixmap from my widget right ?
drag->setHotSpot(QPoint(drag->pixmap().width()/2,
drag->pixmap().height()));
Qt::DropAction dropAction = drag->exec();
}


I don't understand why I can't get the result I want, I've even tried to load an external picture into the my QDrag pixmap, but the result is the same, always a black square.

Does anybody have a clue on why it is behaving like this ?

Thank you in advance for your answers !

Regards,

Azsde.

anda_skoa
28th April 2015, 17:12
Maybe you can verify that the pixmap is ok.
E.g. have a local pixmap variable that you call save() on before you pass it to setPixmap().
Then check the file.

Cheers,
_

azsde
29th April 2015, 09:09
Maybe you can verify that the pixmap is ok.
E.g. have a local pixmap variable that you call save() on before you pass it to setPixmap().
Then check the file.

Cheers,
_

Hello and thank you for your answer.

Saving the pixmap to a local file gets me a working PNG file that correspond to the pixmap.

So I guess that my pixmap is fine, any other lead on why it is behaving like this ?

Thank you in advance.

Regards,

Azsde.

anda_skoa
29th April 2015, 10:09
Try something very simple:
- create a fixed size QPixmap, say 64x64
- create a QPainter on it
- use QPainter::fillRect() to fill it with a non-black color
- use this pixmap instead of yours

It if works, try your pixmap's size but use the rest of the approach.

Cheers,
_

azsde
4th May 2015, 09:59
Try something very simple:
- create a fixed size QPixmap, say 64x64
- create a QPainter on it
- use QPainter::fillRect() to fill it with a non-black color
- use this pixmap instead of yours

It if works, try your pixmap's size but use the rest of the approach.

Cheers,
_

Didn't have to try that, I tried the code I had on two other computers (Linux and Windows), and it works, no black square.
So I guess the problem is caused by my computer.

Thanks anyways :)

Regards,

Azsde.

anda_skoa
4th May 2015, 13:03
Could be something like color depth.
E.g. image in 32bit depth, system not configured for 32bit depth, etc.

Cheers,
_

wagmare
5th May 2015, 05:53
check how the other drag images (not your application) on your OS . ex: Internet, some windows application or qt drag drop application . because i also faced some issue. my pixmap what i was dragginh looked completely blurred but on other PC it was fine . so i checked other application drag images and it also shows similar kind of result .. it may be a problem with your OS.