add:添加文件路径支持拖入。
This commit is contained in:
parent
2bfddf1ef7
commit
e1ef813032
@ -30,6 +30,7 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
|
||||
include_directories(3rd)
|
||||
include_directories(src)
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
MainWidget.cpp
|
||||
@ -40,6 +41,7 @@ set(PROJECT_SOURCES
|
||||
resource/ico.rc src/attribute_edit.ui src/attribute_edit.h
|
||||
src/attribute_edit.cpp flatgray.qrc
|
||||
src/data_edit.h src/data_edit.cpp src/data_edit.ui
|
||||
src/QCustomQLineEdit.h src/QCustomQLineEdit.cpp
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
|
@ -961,11 +961,16 @@ bool MainWidget::format_xml()
|
||||
if (xml_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
if (!xml_.handle_save(xml_path)) {
|
||||
CUtil::msg(this, u8"格式化失败");
|
||||
|
||||
if (!CUtil::affirm(this, u8"确认", u8"重排版内容将会覆盖源文件,请确认是否需要备份,继续?")) {
|
||||
return false;
|
||||
}
|
||||
CUtil::msg(this, u8"格式化结束");
|
||||
|
||||
if (!xml_.handle_save(xml_path)) {
|
||||
CUtil::msg(this, u8"重排版内容失败");
|
||||
return false;
|
||||
}
|
||||
CUtil::msg(this, u8"重排版内容结束");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1056</width>
|
||||
<width>1102</width>
|
||||
<height>682</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -35,7 +35,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="edStatus"/>
|
||||
<widget class="QCustomQLineEdit" name="edStatus"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbConfig"/>
|
||||
@ -57,7 +57,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnFormat">
|
||||
<property name="text">
|
||||
<string>格</string>
|
||||
<string>重排版</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -87,7 +87,7 @@
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -142,7 +142,7 @@
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -227,9 +227,6 @@
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
@ -247,9 +244,6 @@
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
@ -329,6 +323,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QCustomQLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>QCustomQLineEdit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>btnSelectFile</tabstop>
|
||||
<tabstop>edStatus</tabstop>
|
||||
|
36
src/QCustomQLineEdit.cpp
Normal file
36
src/QCustomQLineEdit.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "QCustomQLineEdit.h"
|
||||
|
||||
QCustomQLineEdit::QCustomQLineEdit(QWidget* parent) : QLineEdit(parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void QCustomQLineEdit::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
QLineEdit::dragEnterEvent(event);
|
||||
}
|
||||
|
||||
void QCustomQLineEdit::dragMoveEvent(QDragMoveEvent* event)
|
||||
{
|
||||
}
|
||||
|
||||
void QCustomQLineEdit::dropEvent(QDropEvent* event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
if (mimeData->hasUrls()) {
|
||||
QList<QUrl> urls = mimeData->urls();
|
||||
if (urls.size() > 0) {
|
||||
QString file_name = urls.at(0).toLocalFile();
|
||||
setText(file_name);
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
QLineEdit::dropEvent(event);
|
||||
}
|
||||
|
||||
QCustomQLineEdit::~QCustomQLineEdit()
|
||||
{
|
||||
}
|
27
src/QCustomQLineEdit.h
Normal file
27
src/QCustomQLineEdit.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef QCUSTOMQLINE
|
||||
#define QCUSTOMQLINE
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
class QCustomQLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QCustomQLineEdit(QWidget* parent = nullptr);
|
||||
~QCustomQLineEdit() override;
|
||||
|
||||
protected:
|
||||
// 拖动文件到窗口 触发
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
// 拖动文件到窗口移动文件 触发
|
||||
void dragMoveEvent(QDragMoveEvent* event);
|
||||
// 拖动文件到窗口释放文件触发
|
||||
void dropEvent(QDropEvent* event);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user