From b7b83e53bf97e49336732318bafd598254ccf4a4 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Fri, 15 Dec 2023 17:53:18 +0800 Subject: [PATCH] fix filedialog path error --- src/module/cursorthemewidget.cpp | 4 ++-- src/module/globalthemewidget.cpp | 4 ++-- src/module/grubthemewidget.cpp | 2 +- src/module/iconthemewidget.cpp | 4 ++-- src/module/plymouththemewidget.cpp | 4 ++-- src/module/savepathdialog.cpp | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/module/cursorthemewidget.cpp b/src/module/cursorthemewidget.cpp index 2cb25db..38bc9b2 100644 --- a/src/module/cursorthemewidget.cpp +++ b/src/module/cursorthemewidget.cpp @@ -245,7 +245,7 @@ void CursorThemeWidget::initRightWidget() // 如果获取的对象是合法的CursorEditWidget对象 if (clickedWidget) { // 弹出文件选择对话框,让用户选择一个SVG文件 - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), "", tr("SVG file (*.svg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)")); // 如果用户选择了文件,且文件路径不为空 if (!newFilePath.isEmpty()) { // 将widgetName和newFilePath插入到m_customiconpathmap中,以便后续可以通过widgetName找到自定义图标路径 @@ -305,7 +305,7 @@ void CursorThemeWidget::initRightWidget() // 判断获取的CursorEditWidget对象是否为空,如果不为空,则继续执行下面的代码 if (clickedWidget) { // 使用QFileDialog::getOpenFileName函数打开一个文件选择对话框,选择一个SVG文件 - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), "", tr("SVG file (*.svg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)")); // 判断选择的文件路径是否为空,如果不为空,则执行下面的代码 if (!newFilePath.isEmpty()) { diff --git a/src/module/globalthemewidget.cpp b/src/module/globalthemewidget.cpp index ae337d1..c29a222 100644 --- a/src/module/globalthemewidget.cpp +++ b/src/module/globalthemewidget.cpp @@ -232,7 +232,7 @@ void GlobalThemeWidget::initCoverWidget() coverlayout->addWidget(tip); cover->setLayout(coverlayout); connect(m_coverbtn, &QPushButton::clicked, this, [=]() { - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png *.jpg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), QDir::homePath(), tr("Picture file (*.png *.jpg)")); if (newFilePath.isEmpty()) { newFilePath = m_coverpath; }else{ @@ -299,7 +299,7 @@ void GlobalThemeWidget::initWallPaperWidget() wallpaperbtn->setIconSize(QSize(130,80)); connect(wallpaperbtn, &QPushButton::clicked, this, [=]() { - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png *.jpg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), QDir::homePath(), tr("Picture file (*.png *.jpg)")); if (!newFilePath.isEmpty()) { if(FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")){ diff --git a/src/module/grubthemewidget.cpp b/src/module/grubthemewidget.cpp index df6a2cf..700f5df 100644 --- a/src/module/grubthemewidget.cpp +++ b/src/module/grubthemewidget.cpp @@ -97,7 +97,7 @@ void GrubThemeWidget::initEditWidget() connect(m_showBtn, &QPushButton::clicked, this, [=]() { // 弹出文件选择对话框,选择图片文件 - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), "", tr("Picture file (*.png)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select picture file"), QDir::homePath(), tr("Picture file (*.png)")); // 如果选择的文件路径不为空 if (!newFilePath.isEmpty()) { diff --git a/src/module/iconthemewidget.cpp b/src/module/iconthemewidget.cpp index 2a4cd14..6645cc3 100644 --- a/src/module/iconthemewidget.cpp +++ b/src/module/iconthemewidget.cpp @@ -110,7 +110,7 @@ void IconThemeWidget::initEditWidget() clickedWidget = qobject_cast(widget); if (clickedWidget) { - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), "", tr("SVG file (*.svg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)")); if (!newFilePath.isEmpty()) { m_customiconpathmap->insert(widgetName, newFilePath); @@ -282,7 +282,7 @@ void IconThemeWidget::initSystemEditWidget() if (clickedWidget) { // 显示一个文件选择对话框,让用户选择一个SVG文件。将文件路径保存到newFilePath变量中。 - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), "", tr("SVG file (*.svg)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select SVG file"), QDir::homePath(), tr("SVG file (*.svg)")); if (!newFilePath.isEmpty()) { //check if(FileCheck::isLegalIconFile(newFilePath)){ diff --git a/src/module/plymouththemewidget.cpp b/src/module/plymouththemewidget.cpp index a61228b..ce978fa 100644 --- a/src/module/plymouththemewidget.cpp +++ b/src/module/plymouththemewidget.cpp @@ -106,7 +106,7 @@ void PlymouthThemeWidget::initEditWidget() addButton->setFixedSize(36,36); connect(addButton, &QPushButton::clicked, this, [=]() { if(pic->isChecked()){ - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select Png file"), "", tr("Png file (*.png)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select Png file"), QDir::homePath(), tr("Png file (*.png)")); if (!newFilePath.isEmpty()) { if(FileCheck::isLegalPlymouthPicFile(newFilePath)){ QPixmap pixmap(newFilePath); @@ -121,7 +121,7 @@ void PlymouthThemeWidget::initEditWidget() } } else{ - QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select MP4 file"), "", tr("MP4 file (*.mp4)")); + QString newFilePath = QFileDialog::getOpenFileName(this, tr("Select MP4 file"), QDir::homePath(), tr("MP4 file (*.mp4)")); if (!newFilePath.isEmpty()) { if(FileCheck::isLegalMP4File(newFilePath)){ QPixmap pixmap(newFilePath); diff --git a/src/module/savepathdialog.cpp b/src/module/savepathdialog.cpp index aad6a52..f31dd41 100644 --- a/src/module/savepathdialog.cpp +++ b/src/module/savepathdialog.cpp @@ -51,7 +51,7 @@ QString SavePathDialog::getSavePath() void SavePathDialog::onModifyBtnClicked() { - QString newFilePath = QFileDialog::getExistingDirectory(this); + QString newFilePath = QFileDialog::getExistingDirectory(this, tr("Select Directory"),QDir::homePath()); if(newFilePath != nullptr){ m_savepath = newFilePath; emit savePathUpdate(newFilePath);