代码拉取完成,页面将自动刷新
#include "FileDialogWidget.h"
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QFileDialog>
#include <QMimeData>
#include <QUrl>
#include <QDebug>
FileDialogWidget::FileDialogWidget(void)
{
QFont font("微软雅黑", 12);
lineEdit = new QLineEdit(&box);
but_open = new QPushButton("打开文件", &box);
but_ctr = new QPushButton(" ", &box);
box.resize(800, 45);
lineEdit->move(5, 5);
lineEdit->resize(595, 35);
lineEdit->setFont(font);
lineEdit->setAcceptDrops(true); // 允许拖放操作
lineEdit->clear();
but_open->move(605, 5);
but_open->resize(75, 35);
but_open->setFont(font);
but_ctr->move(685, 5);
but_ctr->resize(75, 35);
but_ctr->setFont(font);
but_ctr->setEnabled(false);
connect(but_open, &QPushButton::clicked, this, &FileDialogWidget::openFileDialog);
connect(but_ctr, &QPushButton::clicked, this, &FileDialogWidget::but_ctr_sloot);
}
FileDialogWidget::~FileDialogWidget()
{
delete (but_open);
but_open = NULL;
delete (lineEdit);
lineEdit = NULL;
}
void FileDialogWidget::set(QWidget *parent, int x, int y, const char *str, const char *bot_name)
{
box.setParent(parent); // 设置父窗口
box.move(x, y);
if (str != NULL)
{
lineEdit->setText(QString::fromUtf8(str));
}
if (bot_name != NULL)
{
but_ctr->setText(QString::fromUtf8(bot_name));
}
}
bool FileDialogWidget::is_path(void)
{
if (get_path().length() < 3)
{
return false;
}
QFileInfo fileInfo(get_path());
QString path = fileInfo.absolutePath();// 提取路径部分
QDir dir(path); // 替换为你要遍历的目录路径
if (dir.exists())
{
return true;
}
return false;
}
QString FileDialogWidget::get_path(void)
{
return lineEdit->text();
}
void FileDialogWidget::openFileDialog()
{
QString filePath = QFileDialog::getOpenFileName(this, "Open File", "", "All Files (*.*)");
if (!filePath.isEmpty())
{
lineEdit->setText(filePath);
bool path_en = is_path();
emit path_Signal(path_en); // 发射信号
but_ctr->setEnabled(path_en);
}
}
void FileDialogWidget::but_ctr_sloot()
{
if (is_path())
{
emit ctrl_Signal(); // 发射信号
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。