From 02f4d8e3616bec9f3d2e6fb60b002873c8728e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E9=9D=99?= Date: Wed, 11 Jan 2023 16:13:50 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20bug155583=20bug154391=20QMessagebox?= =?UTF-8?q?=E6=9C=AA=E5=B1=85=E4=B8=AD=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=20QDialog=E5=9C=A8=E8=AE=BE=E7=BD=AEparent=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widget/messagebox/message-box.cpp | 81 +++++++++++++++---- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp b/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp index 24ba1d6..a978e01 100644 --- a/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp +++ b/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp @@ -32,8 +32,6 @@ #include #include #include -#include "ukuistylehelper/ukuistylehelper.h" -#include "windowmanager/windowmanager.h" #include "private/qlabel_p.h" #include "private/qdialog_p.h" @@ -493,11 +491,11 @@ void MessageBox::setWindowModality(Qt::WindowModality windowModality) { QDialog::setWindowModality(windowModality); - if (parentWidget() && windowModality == Qt::WindowModal) { - setParent(parentWidget(), Qt::Sheet); - } else { - setParent(parentWidget(), Qt::Dialog); - } +// if (parentWidget() && windowModality == Qt::WindowModal) { +// setParent(parentWidget(), Qt::Sheet); +// } else { +// setParent(parentWidget(), Qt::Dialog); +// } setDefaultButton(d_func()->mDefaultButton); } @@ -709,6 +707,7 @@ MessageBoxPrivate::MessageBoxPrivate() : mCheckbox(nullptr), mEscapeButton(nullp MessageBoxPrivate::~MessageBoxPrivate() { + /* if (nullptr != mLabel) { delete mLabel; } @@ -728,6 +727,7 @@ MessageBoxPrivate::~MessageBoxPrivate() if (nullptr != mDetailButton) { delete mDetailButton; } + */ } void MessageBoxPrivate::init(const QString &title, const QString &text) @@ -1407,15 +1407,68 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind } } } + + for (QMessageBox *mb : p->findChildren()) { + if (mb->icon() == options()->icon() && mb->windowTitle() == options()->windowTitle() && mb->text() == options()->text() + && mb->informativeText() == options()->informativeText() && mb->detailedText() == options()->detailedText()) { + if (mb->parentWidget() != nullptr && windowModality == Qt::WindowModal) { + ///QDialog center in parent + mMessageBox->setParent(p, Qt::Sheet); + } + else{ + ///QDialog center in parent + mMessageBox->setParent(p, Qt::Dialog); + } + } + } } } - + else{ + if(windowModality == Qt::WindowModal) + mMessageBox->setWindowFlag(Qt::Sheet); + else + mMessageBox->setWindowFlag(Qt::Dialog); + } mMessageBox->setuplayout(); - if (parent && !mMessageBox->isVisible()) { - mMessageBox->move(QPoint((parent->width() - mMessageBox->width()) / 2, (parent->height() - mMessageBox->height()) / 2) - + QPoint(parent->x(), parent->y())); +/* + if (!mMessageBox->isVisible()) { + if(parent){ + + QWidget *p = mMessageBox->find(parent->winId()); + int x = (p->width() - mMessageBox->width()) > 0 ? (p->width() - mMessageBox->width()) / 2 : 0; + int y = (p->height() - mMessageBox->height()) > 0 ? (p->height() - mMessageBox->height()) / 2 : 0; + QPoint gloabP = QPoint(x, y) + p->mapToGlobal(p->pos()); + qDebug() << "gloabP...." << gloabP; + QPoint point = p->mapFromGlobal(gloabP); + qDebug() << "point....." << point; + if (windowModality == Qt::WindowModal) { + qDebug() << "WindowModal............"; + mMessageBox->setParent(p, Qt::Sheet); + } + else{ + qDebug() << "Dialog............"; + mMessageBox->setParent(p, Qt::Dialog); + } + +// mMessageBox->move(point); + qDebug() << "mMessageBox parent......" << p << p->geometry() << p->mapToGlobal(p->pos()); + qDebug() << "mMessageBox ....." << mMessageBox << mMessageBox->geometry(); + + } + else{ + int number = QApplication::desktop()->screenNumber(QCursor::pos()); + if(number<0){ + number=0; + } + QSize size = QApplication::screens().at(number)->availableGeometry().size(); +// qDebug() << "availableGeometry......" << size << QApplication::screens().at(number)->availableSize(); + mMessageBox->move(QPoint((size.width() - mMessageBox->width()) / 2, (size.height() - mMessageBox->height()) / 2)); + + } + + // if (QWidget *p = mMessageBox->find(parent->winId())) { // qDebug() << "isvisible....." << mMessageBox->isVisible(); @@ -1430,6 +1483,7 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind // qDebug() << "parent11111111............" << mMessageBox->geometry() << parent->geometry() << p->geometry(); // } } +*/ QString platform = QGuiApplication::platformName(); if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) @@ -1452,11 +1506,6 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind } } mMessageBox->show(); - - Q_UNUSED(parent); - Q_UNUSED(windowFlags); - Q_UNUSED(windowModality); - return true; }