allowed to DnD file on window for easier testing
This commit is contained in:
parent
0469afeb05
commit
81a289c4d0
|
@ -3,10 +3,13 @@
|
||||||
|
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
|
, m_filePath(R"(E:\16bit-raw-argb-affinityphoto.psd)")
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +19,31 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasUrls()) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QMainWindow::dragEnterEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
event->acceptProposedAction();
|
||||||
|
|
||||||
|
const QMimeData * mimeData = event->mimeData();
|
||||||
|
|
||||||
|
if (mimeData->hasUrls()) {
|
||||||
|
const QList<QUrl> &urls = mimeData->urls();
|
||||||
|
if (!urls.isEmpty()) {
|
||||||
|
m_filePath = urls.first().toLocalFile();
|
||||||
|
ui->label->setText(m_filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_clicked()
|
void MainWindow::on_pushButton_clicked()
|
||||||
{
|
{
|
||||||
|
@ -23,7 +51,7 @@ void MainWindow::on_pushButton_clicked()
|
||||||
qDebug() << QImageReader::supportedImageFormats();
|
qDebug() << QImageReader::supportedImageFormats();
|
||||||
|
|
||||||
// 后面的文件改成 psd 文件的路径
|
// 后面的文件改成 psd 文件的路径
|
||||||
QScopedPointer< QImageReader> ir(new QImageReader(R"(E:\ff.psd)"));
|
QScopedPointer< QImageReader> ir(new QImageReader(m_filePath));
|
||||||
qDebug() << ir->canRead();
|
qDebug() << ir->canRead();
|
||||||
QImage read = ir->read();
|
QImage read = ir->read();
|
||||||
if (read.isNull()) {
|
if (read.isNull()) {
|
||||||
|
|
|
@ -15,10 +15,16 @@ public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
|
QString m_filePath;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -10,36 +10,32 @@
|
||||||
<height>600</height>
|
<height>600</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="geometry">
|
<item>
|
||||||
<rect>
|
<widget class="QLabel" name="label">
|
||||||
<x>0</x>
|
<property name="text">
|
||||||
<y>0</y>
|
<string>TextLabel</string>
|
||||||
<width>801</width>
|
</property>
|
||||||
<height>561</height>
|
<property name="alignment">
|
||||||
</rect>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
</widget>
|
||||||
<string>TextLabel</string>
|
</item>
|
||||||
</property>
|
<item>
|
||||||
</widget>
|
<widget class="QPushButton" name="pushButton">
|
||||||
<widget class="QPushButton" name="pushButton">
|
<property name="text">
|
||||||
<property name="geometry">
|
<string>Display Image</string>
|
||||||
<rect>
|
</property>
|
||||||
<x>0</x>
|
</widget>
|
||||||
<y>570</y>
|
</item>
|
||||||
<width>801</width>
|
</layout>
|
||||||
<height>24</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>PushButton</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user