From 32e7e649ae58cc65a9a878f12eb605116a8ac151 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Thu, 3 Apr 2025 18:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Linxu=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/connectionDialog.cpp | 4 ++-- source/mainwindow.cpp | 20 ++++++++------------ source/messageDialog.cpp | 6 +++--- source/modelInfoEditDialog.cpp | 4 ++-- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/source/connectionDialog.cpp b/source/connectionDialog.cpp index 91143a8..d8de7f0 100644 --- a/source/connectionDialog.cpp +++ b/source/connectionDialog.cpp @@ -15,8 +15,8 @@ ConnectionDialog::ConnectionDialog(QWidget *parent) ui->setupUi(this); if(QSysInfo::kernelType() == "linux") { - //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,去边框后是简单的解决上述问题的方法 - setWindowFlags(Qt::FramelessWindowHint); + //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用 + setWindowFlags(windowFlags() & ~Qt::Dialog); setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;}"); } setModal(true); diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index ca065e3..6af671a 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -99,12 +99,8 @@ void MainWindow::showMessageDialog(MessageDialogType type,const QString& strTitl } m_pMessageDialog->setMessage(type, strTitle, strContent); - // int nX = this->geometry().x() + (this->width() - m_pMessageDialog->width()) * 0.5; - // int nY = this->geometry().y() + (this->height() - m_pMessageDialog->height()) * 0.5; - // m_pMessageDialog->move(nX, nY); - QRect parentFrame = this->frameGeometry(); // 获取父窗口的完整几何信息(包含边框和标题栏),适用于快平台对其 - int nX = parentFrame.x() + (parentFrame.width() - m_pMessageDialog->width()) / 2; - int nY = parentFrame.y() + (parentFrame.height() - m_pMessageDialog->height()) / 2; + int nX = this->geometry().x() + (this->width() - m_pMessageDialog->width()) * 0.5; + int nY = this->geometry().y() + (this->height() - m_pMessageDialog->height()) * 0.5; m_pMessageDialog->move(nX, nY); //m_pMessageDialog->raise(); // if(type == type_question) @@ -146,12 +142,12 @@ void MainWindow::onActionTrigger_connect() connect(m_pConnectionDialog, &ConnectionDialog::addConnection, this, &MainWindow::onSIG_addConnection); } - // int nX = this->geometry().x() + (this->width() - m_pConnectionDialog->width()) * 0.5; - // int nY = this->geometry().y() + (this->height() - m_pConnectionDialog->height()) * 0.5; - // m_pConnectionDialog->move(nX, nY); - QPoint centerPos = this->mapToGlobal(this->rect().center()); - centerPos -= QPoint(m_pConnectionDialog->width()/2, m_pConnectionDialog->height()/2); - m_pConnectionDialog->move(centerPos); + int nX = this->geometry().x() + (this->width() - m_pConnectionDialog->width()) * 0.5; + int nY = this->geometry().y() + (this->height() - m_pConnectionDialog->height()) * 0.5; + m_pConnectionDialog->move(nX, nY); + // QPoint centerPos = this->mapToGlobal(this->rect().center()); + // centerPos -= QPoint(m_pConnectionDialog->width()/2, m_pConnectionDialog->height()/2); + // m_pConnectionDialog->move(centerPos); m_pConnectionDialog->show(); } void MainWindow::onActionTrigger_disconnect() diff --git a/source/messageDialog.cpp b/source/messageDialog.cpp index a3645be..8bf6035 100644 --- a/source/messageDialog.cpp +++ b/source/messageDialog.cpp @@ -11,9 +11,9 @@ MessageDialog::MessageDialog(QWidget *parent) if(QSysInfo::kernelType() == "linux") { - //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,去边框后是简单的解决上述问题的方法 - setWindowFlags(Qt::FramelessWindowHint); - setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(250,250,250);}"); + //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用 + setWindowFlags(windowFlags() & ~Qt::Dialog); + setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(245,245,245);}"); } else { diff --git a/source/modelInfoEditDialog.cpp b/source/modelInfoEditDialog.cpp index a4b06d9..e18153e 100644 --- a/source/modelInfoEditDialog.cpp +++ b/source/modelInfoEditDialog.cpp @@ -17,8 +17,8 @@ ModelInfoEditDialog::ModelInfoEditDialog(QWidget *parent) ui->setupUi(this); if(QSysInfo::kernelType() == "linux") { - //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,去边框后是简单的解决上述问题的方法 - setWindowFlags(Qt::FramelessWindowHint); + //Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用 + setWindowFlags(windowFlags() & ~Qt::Dialog); setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(250,250,250);}"); } initialize();