mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-13 18:42:03 +08:00
优化对话框
This commit is contained in:
@@ -2,29 +2,65 @@
|
||||
#include <QGridLayout>
|
||||
#include <DLabel>
|
||||
#include <DPushButton>
|
||||
#include <DTitlebar>
|
||||
|
||||
|
||||
MessageBox::MessageBox(DWidget *parent){
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void MessageBox::information(QString title, QString text){
|
||||
DMainWindow *messageBox = new DMainWindow(this->parent);
|
||||
void MessageBox::ShowMessageBox(QString iconPath, QString title, QString text){
|
||||
DMainWindow *messageBox = new DMainWindow();
|
||||
DWidget *widget = new DWidget();
|
||||
QGridLayout *layout = new QGridLayout();
|
||||
DPushButton *ok = new DPushButton("确定");
|
||||
QObject::connect(ok, &DPushButton::clicked, messageBox, [messageBox](){
|
||||
messageBox->close();
|
||||
});
|
||||
layout->addWidget(new DLabel("<img src=':/Icon/MessageBox/dialog-information.svg'>"));
|
||||
DTitlebar *bar = messageBox->titlebar();
|
||||
bar->setTitle(title);
|
||||
bar->setIcon(QIcon(":/Icon/deepin-wine-runner.svg"));
|
||||
bar->setMenuVisible(false);
|
||||
bar->setBackgroundTransparent(true);
|
||||
layout->addWidget(new DLabel("<img src='" + iconPath + "'>"));
|
||||
layout->addWidget(new DLabel(text), 0, 1);
|
||||
layout->addWidget(ok, 1, 0, 1, 2);
|
||||
widget->setLayout(layout);
|
||||
//messageBox->setEnableSystemResize(true);
|
||||
messageBox->setEnableBlurWindow(false);
|
||||
messageBox->setEnableSystemResize(false);
|
||||
messageBox->setWindowFlags(messageBox->windowFlags() &~ Qt::WindowMaximizeButtonHint &~ Qt::Dialog &~ Qt::WindowMinimizeButtonHint);
|
||||
messageBox->setCentralWidget(widget);
|
||||
messageBox->setWindowTitle(title);
|
||||
// 设置窗口顶置
|
||||
messageBox->setWindowFlag(Qt::WindowStaysOnTopHint);
|
||||
messageBox->show();
|
||||
messageBox->resize(messageBox->frameSize().width(), messageBox->frameSize().height());
|
||||
|
||||
//// 根据窗口信息获取中点
|
||||
// 获取窗口信息
|
||||
int parentWindowX = this->parent->frameGeometry().x();
|
||||
int parentWindowY = this->parent->frameGeometry().y();
|
||||
int parentWindowWidth = this->parent->frameGeometry().width();
|
||||
int parentWindowHeight = this->parent->frameGeometry().height();
|
||||
int messageBoxWidth = messageBox->frameSize().width();
|
||||
int messageBoxHeight = messageBox->frameSize().height();
|
||||
// 计算 X 坐标
|
||||
int x = parentWindowX + ((parentWindowWidth / 2) - (messageBoxWidth / 2));
|
||||
int y = parentWindowY + ((parentWindowHeight / 2) - (messageBoxHeight / 2));
|
||||
messageBox->move(x, y);
|
||||
qDebug() << parentWindowX;
|
||||
qDebug() << parentWindowY;
|
||||
qDebug() << parentWindowWidth;
|
||||
qDebug() << parentWindowHeight;
|
||||
qDebug() << messageBoxWidth;
|
||||
qDebug() << messageBoxHeight;
|
||||
qDebug() << x << y;
|
||||
}
|
||||
|
||||
void MessageBox::information(QString title, QString text){
|
||||
ShowMessageBox(":/Icon/MessageBox/dialog-information.svg", title, text);
|
||||
}
|
||||
|
||||
void MessageBox::critical(QString title, QString text){
|
||||
ShowMessageBox(":/Icon/MessageBox/dialog-error.svg", title, text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user