PDA

View Full Version : Qgraphicsitem drag and drop



erfan
8th June 2012, 15:38
i have a problem with qt i want to drag an image and use of Qgraphicspixmapitem and dragenterevent but it doesnt appear in the console ? but other function like hoverEnterEvent work corectly??? hear is the code: please help?
:

#ifndef BUTTON_H
#define BUTTON_H

#include <QGraphicsObject>
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent>
#include <QDrag>

class button : public QGraphicsPixmapItem
{
public:
button(const QPixmap &);
button(){setAcceptHoverEvents(1);
setAcceptDrops(true);}
void changepic( QPixmap,int ,int);
void mousePressEvent(QGraphicsSceneMouseEvent*event);
void dragenterEvent(QGraphicsSceneDragDropEvent *event){

event->setAccepted(1);
qDebug("drag");
}
void dropEvent(QGraphicsSceneDragDropEvent *event){
qDebug("drop");
}

void hoverEnterEvent(QGraphicsSceneHoverEvent *event){

// do something
// this->setPos(this->x()+10,this->y()+10);

qDebug("k");

QGraphicsItem::hoverMoveEvent(event);
}
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);



};

#endif // BUTTON_H

wysota
8th June 2012, 21:22
There is a difference between dragenterEvent and dragEnterEvent.

erfan
9th June 2012, 05:17
hi everyone

can anybody give me a simple example that i can drag and drop QGraphicsItem by using of :

void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
very thanks.