UI 를 초기화할 때 setAcceptDrops(TRUE) 를 해준다.
void myWidget::dragEnterEvent(QDragEnterEvent * event) { event->accept(QUriDrag::canDecode(event));
QUriDrag 대신에 QTextDrag, QImageDrag 등도 쓴다.
void myWidget::dropEvent(QDropEvent * event)
{
QString text;
QStringList files;
if ( QTextDrag::decode(event, text) )
{
QMessageBox::information(this, text, text, QMessageBox::Ok );
}
else if ( QUriDrag::decodeLocalFiles(event, files) )
{
for ( int i=0; i<files.count(); ++i )
{
QMessageBox::information(this, files[i], text, QMessageBox::Ok );
}
}
}