MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
edit = new QTextEdit;
this->setCentralWidget(edit);
setAcceptDrops(true);
this->setWindowTitle(tr("Text Editor"));
}
MainWindow::~MainWindow()
{
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if(event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent* event)
{
QList<QUrl> uri = event->mimeData()->urls();
if(uri.isEmpty())
return;
QString file = uri.first().toLocalFile();
if(file.isEmpty())
return;
this->setWindowTitle(tr("%1 -- %2").arg(file).arg("Drag File"));
}