You're dropping on a wrong widget. The text edit has its own drop handler which is displaying text carried by the drag and it happens that URLs are stored as text, so it's a perfectly good drag for the text edit, so it handles the event and doesn't pass it to a parent widget where your drop handler resides. Try dropping
outside the text edit.
Or from the C++ Gui programming Book
Suppose the QTextEdit is inside a main Window then
MainWindow::MainWindow( ... ){
[...]
textEdit->setAcceptDrops( false );
setAcceptDrops( true );
}
// accept if you can decode the mime data
}
// get the file from the mime Data
readFile( file );
}
MainWindow::MainWindow( ... ){
[...]
textEdit->setAcceptDrops( false );
setAcceptDrops( true );
}
void MainWindow::dragEnterEvent( QDragEnterEvent *e ) {
// accept if you can decode the mime data
}
void MainWindow::dropEvent( QDropEvent *e ) {
// get the file from the mime Data
readFile( file );
}
To copy to clipboard, switch view to plain text mode
Bookmarks