Re: how to use dragMove()..
try this:
Code:
{
if (event->button() == Qt::LeftButton)
{
mimeData->setText("myDrageLabel");
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
if (dropAction == Qt::MoveAction)
{
close();
update();
}
}
}
in your base class, in which you are using drag object (say myWidget)
myWidget
::myWidget(QWidget *parent
) : {
setAcceptDrops(true);
...
}
{
if (event->mimeData()->hasText())
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}
{
if (event->mimeData()->hasText())
{
//QString plainText = event->mimeData()->text();
QPoint dropPos
= event
->pos
();
QDragObject *drobj;
if ( pixmap() )
drobj = new QImageDrag( pixmap()->convertToImage(), this );
drobj->move(dropPos);
drobj->show();
if (children().contains(event->source()))
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
event->acceptProposedAction();
}
}
else
{
event->ignore();
}
}
Re: how to use dragMove()..
Hi Rajesh,
thanks for your code. but unfortunately i'm using older version of qt(qt-3.3.5). in that i dont have QMimeData etc. but let me go through the code and try to adapt with teh functions in qt-3.3.5. but i think the problem in my code was that i used QPixmap::load() function to display the image. and then drag this image to the drop widget. this is my code:
Code:
static void addStuff
( QWidget * parent,
bool image,
bool secret
= FALSE ) {
if(image)
{
drag *drg = new drag(parent);
drag *drg1 = new drag(parent);
tll->addWidget( drg );
tll->addWidget( drg1 );
if(stuff.load( "trolltech.bmp" )); ----i think this caused my image not to be moved---
itemname[0]=1;
stuff1.load( "butterfly.png" );
drg->setPixmap( stuff );
drg1->setPixmap( stuff1 );
}
else
{
drop *drp= new drop(parent);
drop *drp1= new drop(parent);
tll->addWidget( drp );
tll->addWidget( drp1 );
drp->setText("Drop the items");
drp
->setFont
(QFont("Helvetica",
12));
drp1->setText("Drag and Drop");
drp1
->setFont
(QFont("Helvetica",
12));
}
}
.
thinking of using QIconview. any suggestions ?
Re: how to use dragMove()..
I dont know about Qpixmap::load. but in your previous code you creating a new object and not deleteing old object. so it will create a copy of new widget.
mainly whenever you create a new widget then delete or close old widget.