Fix some of the broken native dialogs

This commit is contained in:
GriffinR
2025-05-12 22:50:06 -04:00
parent 7239f6f4a3
commit b1f531924f
3 changed files with 14 additions and 4 deletions

View File

@@ -38,7 +38,8 @@ public:
class InfoMessage : public Message {
public:
InfoMessage(const QString &message, QWidget *parent);
static void show(const QString &message, QWidget *parent);
static void show(const QString &message, const QString &informativeText, QWidget *parent);
static void show(const QString &message, QWidget *parent) { InfoMessage::show(message, QString(), parent); }
};
// Basic question message with a 'Yes' and 'No' button.

View File

@@ -1895,7 +1895,8 @@ bool MainWindow::save(bool currentOnly) {
if (success && !porymapConfig.shownInGameReloadMessage) {
// Show a one-time warning that the user may need to reload their map to see their new changes.
InfoMessage::show(QStringLiteral("Reload your map in-game!\n\nIf your game is currently saved on a map you have edited, "
InfoMessage::show(QStringLiteral("Reload your map in-game!"),
QStringLiteral("If your game is currently saved on a map you have edited, "
"the changes may not appear until you leave the map and return."),
this);
porymapConfig.shownInGameReloadMessage = true;

View File

@@ -7,6 +7,13 @@ Message::Message(QMessageBox::Icon icon, const QString &text, QMessageBox::Stand
QMessageBox(icon, QApplication::applicationName(), text, buttons, parent)
{
setWindowModality(Qt::WindowModal);
// QMessageBoxes with stylesheets are not allowed to be native (see Qt's QMessageBoxPrivate::canBeNativeDialog).
// We're preferring the native dialog appearance over Porymap's themes here.
// Frustratingly, it doesn't matter what's in the stylesheet. Even a stylesheet with just comments will trigger this,
// and manually setting the Message's stylesheet to an empty string doesn't undo this, so we need to explicitly clear
// the stylesheet attribute in order to use native dialogs.
setAttribute(Qt::WA_StyleSheet, false);
}
ErrorMessage::ErrorMessage(const QString &message, QWidget *parent) :
@@ -75,8 +82,9 @@ int QuestionMessage::show(const QString &message, QWidget *parent) {
return msgBox.exec();
};
void InfoMessage::show(const QString &message, QWidget *parent) {
void InfoMessage::show(const QString &message, const QString &informativeText, QWidget *parent) {
auto msgBox = new InfoMessage(message, parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setInformativeText(informativeText);
msgBox->open();
};
}