PDA

View Full Version : drag and drop



vijay anandh
26th April 2006, 11:32
Hi All

I am vijay using VS 2005 with Qt 4.1. I do drag and drop operations from one label pixmap to another label . In My source code

i have written this statement.

void CMyClass : dropEvent(QDropEvent *event)
{
QLabel *child=static_cast<QLabel*>(childAt(event->pos()));
}
childAt statement returns the corresponding widget located at event->pos( when we release the mouse). This works fine when we release the mouse on label box. but if we release the mouse on text box or frame the program get crossing. I want to solve this problem. If we release the mouse on other widgets except label, it should ignore

Can you help me.

thanks and regards
vijay

jpn
26th April 2006, 11:46
Instead of the dialog/window/whatever widget, you could implement the drag and drop events in all individual labels (either by subclassing or by event filters).
If you don't want to do that, you could also use dynamic cast to check whether the underlying widget is of wanted type. This is a bit uglier than the first solution, but needs less effort with the code you already have.