QErrorMessage Icon
-
@JonB I was hoping some form of setStyle() might do the trick?
Time to go mining the source again...
It's clear that there was some intention at some stage to provide that sort of capability:
const char * const messages[] = { QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"), QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"), QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Information:"), };and the private data holds the icon style:
d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));So if there were an easy way to access d->icon ...
This nasty hack:
// // Hack to access the Icon displayed by QErrorMessage // if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr) { eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning)); }Got me:

Which I classify as a success!
It's a shame that a better way to handle this isn't exposed.
-
By default the QErrorMessage dialogue displays an "Information" icon.
How can I change it to be a "Warning", or "Error" icon?
Thanks
David -
@Perdrix
That doesn't seem to be exposed. Don't know whether some kind offind<?? *>()would locate the icon for you somehow.QMessageBoxlets you pick the icon, maybe you should use that.@JonB I was hoping some form of setStyle() might do the trick?
Time to go mining the source again...
It's clear that there was some intention at some stage to provide that sort of capability:
const char * const messages[] = { QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"), QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"), QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Information:"), };and the private data holds the icon style:
d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));So if there were an easy way to access d->icon ...
-
@JonB I was hoping some form of setStyle() might do the trick?
Time to go mining the source again...
It's clear that there was some intention at some stage to provide that sort of capability:
const char * const messages[] = { QT_TRANSLATE_NOOP("QErrorMessage", "Debug Message:"), QT_TRANSLATE_NOOP("QErrorMessage", "Warning:"), QT_TRANSLATE_NOOP("QErrorMessage", "Critical Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Fatal Error:"), QT_TRANSLATE_NOOP("QErrorMessage", "Information:"), };and the private data holds the icon style:
d->icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation));So if there were an easy way to access d->icon ...
This nasty hack:
// // Hack to access the Icon displayed by QErrorMessage // if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr) { eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning)); }Got me:

Which I classify as a success!
It's a shame that a better way to handle this isn't exposed.
-
This nasty hack:
// // Hack to access the Icon displayed by QErrorMessage // if (QLabel * eMDI{ errorMessageDialog->findChild<QLabel*>() }; eMDI != nullptr) { eMDI->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning)); }Got me:

Which I classify as a success!
It's a shame that a better way to handle this isn't exposed.
-
P Perdrix has marked this topic as solved on
-
@Perdrix
Well done, but (unless you really want that "Show this message again") I fail to see what this gives over usingQMessageBox. -
@JonB Yes I really, really do want that "Show this message again" checkbox for these messages.
Most of my error messages do use QMessageBox.
D.
-
@Perdrix
Wow! :) Then it's a nice convenience.In your case, what does "this message" again refer to? Just that particular file path in that message?
@JonB Actually the way it's coded at the moment, it applies to all messages "like" that. But the users are discussing whether to ask me to do it on a per file basis).
Specifically the code reads:
{ // // If the file has already been loaded complain // QString errorMessage(tr("File %1 has already been loaded in group %2 (%3)") .arg(file.generic_string().c_str()) .arg(groupId) .arg(frameList.groupName(groupId))); #if defined(_CONSOLE) std::cerr << errorMessage.toUtf8().constData(); #else errorMessageDialog->showMessage(errorMessage, "Already loaded"); #endif return true; } return false; -
@JonB Actually the way it's coded at the moment, it applies to all messages "like" that. But the users are discussing whether to ask me to do it on a per file basis).
Specifically the code reads:
{ // // If the file has already been loaded complain // QString errorMessage(tr("File %1 has already been loaded in group %2 (%3)") .arg(file.generic_string().c_str()) .arg(groupId) .arg(frameList.groupName(groupId))); #if defined(_CONSOLE) std::cerr << errorMessage.toUtf8().constData(); #else errorMessageDialog->showMessage(errorMessage, "Already loaded"); #endif return true; } return false;