代码拉取完成,页面将自动刷新
#include "gmessagebox.h"
#include "dapplication.h"
#include <QStyle>
#include <QPixmap>
#include <QLabel>
#include <QDebug>
DWIDGET_USE_NAMESPACE
GMessageBox::GMessageBox(QWidget *parent): DDialog(parent)
{
}
GMessageBox::GMessageBox(QWidget *parent,
const QString &title,
const QString &text): DDialog(parent)
{
this->setText(text);
this->setTitle(title);
}
GMessageBox::Icon GMessageBox::icon() const
{
return nowIcon;
}
void GMessageBox::setIcon(Icon icon)
{
enum QStyle::StandardPixmap dialogIcon;
nowIcon = icon;
switch(icon)
{
case Icon::NoIcon:
return;
case Icon::Critical:
dialogIcon = (enum QStyle::StandardPixmap)11;
break;
case Icon::Information:
dialogIcon = (enum QStyle::StandardPixmap)9;
break;
case Icon::Question:
dialogIcon = (enum QStyle::StandardPixmap)12;
break;
case Icon::Warning:
dialogIcon = (enum QStyle::StandardPixmap)10;
break;
}
// 获取设备像素比 (适配高分屏)
qreal scaleFactor = this->devicePixelRatioF();
int iconSize = static_cast<int>(64 * scaleFactor); // 基准大小为64px,根据比例调整
QPixmap pixmap = DApplication::style()->standardIcon(dialogIcon).pixmap(iconSize, iconSize);
pixmap.setDevicePixelRatio(scaleFactor); // 设置像素比以确保显示清晰
this->setIconPixmap(pixmap);
this->setWindowIcon(DApplication::style()->standardIcon(dialogIcon));
}
void GMessageBox::setStandardButtonsWithList(QList<StandardButtons> buttons)
{
QStringList buttonsList;
for(StandardButtons i: buttons) {
switch(i) {
case StandardButton::Ok:
buttonsList << tr("OK");
break;
case StandardButton::Save:
buttonsList << tr("Save");
break;
case StandardButton::SaveAll:
buttonsList << tr("Save All");
break;
case StandardButton::Open:
buttonsList << tr("Open");
break;
case StandardButton::Yes:
buttonsList << tr("Yes");
break;
case StandardButton::YesToAll:
buttonsList << tr("Yes To All");
break;
case StandardButton::No:
buttonsList << tr("No");
break;
case StandardButton::NoToAll:
buttonsList << tr("No To All");
break;
case StandardButton::Abort:
buttonsList << tr("Abort");
break;
case StandardButton::Retry:
buttonsList << tr("Retry");
break;
case StandardButton::Ignore:
buttonsList << tr("Ignore");
break;
case StandardButton::Close:
buttonsList << tr("Close");
break;
case StandardButton::Cancel:
buttonsList << tr("Cancel");
break;
case StandardButton::Discard:
buttonsList << tr("Discard");
break;
case StandardButton::Help:
buttonsList << tr("Help");
break;
case StandardButton::Apply:
buttonsList << tr("Apply");
break;
case StandardButton::Reset:
buttonsList << tr("Reset");
break;
case StandardButton::RestoreDefaults:
buttonsList << tr("Restore Defaults");
break;
}
}
for(int i = 0; i < buttonsList.count() - 1; ++i) {
this->addButton(buttonsList.at(i));
}
this->addButton(buttonsList.at(buttonsList.length() - 1), true, ButtonType::ButtonRecommend);
}
void GMessageBox::setText(const QString &text)
{
this->setWindowTitle(text);
QLabel *label = findChild<QLabel*>("MessageLabel");
if (label) {
qDebug() << "Find Label";
label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
label->setAttribute(Qt::WA_TransparentForMouseEvents, false);
}
QString newText = text;
this->setMessage(newText.replace("\\n", "\n"));
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。