Allow dropping of files onto window
This commit is contained in:
parent
d9301bbba0
commit
5a38a2db97
2 changed files with 20 additions and 0 deletions
|
@ -14,6 +14,7 @@ Window::Window(QWidget *parent) :
|
||||||
|
|
||||||
{
|
{
|
||||||
setWindowTitle("fstl");
|
setWindowTitle("fstl");
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
QFile styleFile(":/qt/style.qss");
|
QFile styleFile(":/qt/style.qss");
|
||||||
styleFile.open( QFile::ReadOnly );
|
styleFile.open( QFile::ReadOnly );
|
||||||
|
@ -128,3 +129,18 @@ bool Window::load_stl(const QString& filename)
|
||||||
loader->start();
|
loader->start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasUrls())
|
||||||
|
{
|
||||||
|
auto urls = event->mimeData()->urls();
|
||||||
|
if (urls.size() == 1 && urls.front().path().endsWith(".stl"))
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
load_stl(event->mimeData()->urls().front().toLocalFile());
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,10 @@ public:
|
||||||
explicit Window(QWidget* parent=0);
|
explicit Window(QWidget* parent=0);
|
||||||
bool load_stl(const QString& filename);
|
bool load_stl(const QString& filename);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event);
|
||||||
|
void dropEvent(QDropEvent* event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_open();
|
void on_open();
|
||||||
void on_about();
|
void on_about();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue