tags:

views:

47

answers:

1

In my program I override the dragEnterEvent but it never called, So that I want to know about when it's called?

UPDATE

Here the code

class RealBoard:public QGraphicsScene
{
public:
RealBoard();
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
//void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
// void mousePressEvent(QGraphicsSceneMouseEvent *event);
};


RealBoard::RealBoard():QGraphicsScene()
{
setSceneRect(-10,-10,620,620);
}

void RealBoard::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
exit(0);
// addItem(temp);
}

void RealBoard::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
/*
QGraphicsScene::dragLeaveEvent(event);
tempCoin->setZValue(0);
delete temp;
temp=NULL;
*/
exit(0);
}

/*
void RealBoard::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mousePressEvent(event);
QPointF click=event->buttonDownScenePos(Qt::LeftButton);

if(itemAt(click)!=boardP)
{
    itemAt(click)->setZValue(1);
    tempCoin=dynamic_cast<QGraphicsPixmapItem *>(itemAt(click));
   // exit(0);
    temp=new QGraphicsPixmapItem((static_cast<QGraphicsPixmapItem *>(itemAt(click))->pixmap()));
    temp->setPos(itemAt(click)->pos());
    temp->setZValue(0);
    addItem(temp);
    update(temp->pos().x(),temp->pos().y(),75,75);
}
}
*/
A: 

From Qt 4.5.3 documentation,

The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action enters it. More about QDragEnterEvent here

liaK
Can you please say why I the function not called in the above function.
prabhakaran
@ prabhakaran, Your code seems to be fine for me.. Did u check by having a breakpoint at exit(0) at dragEnterEvent(QGraphicsSceneDragDropEvent *event) function??
liaK
@liaK Ya man. Now also it is not reaching the function at all.
prabhakaran
Try having Q_OBJECT macro in the class declaration. I am not sure whether Event handling requires Q_OBJECT macro, but give it a try though, since all the sub classes of QObject should have that macro.
liaK
Robin
@Robin yes, I set those flags as movable. You are correct. The function called when I tried to do so. But in my case there is no need to( and shouldn't) do that.
prabhakaran
@liak how to declare Q_OBJECT
prabhakaran