I want to change the default QMessageBox
title to something else, so that I don't have to call setWindowTitle
for every individual message box.
How is the default window title chosen?
Best way to do this is to subclass QMessageBox , e.g.: class MyMessageBox : public QMessageBox { MyMessageBox() //<-- default constructor { setWindowTitle("Default title goes here"); //QMessageBox function } }; Use MyMessageBox everywhere in the code. Save this answer.
QMessageBox is a commonly used modal dialog to display some informational message and optionally ask the user to respond by clicking any one of the standard buttons on it. Each standard button has a predefined caption, a role and returns a predefined hexadecimal number.
To use the property-based API, construct an instance of QMessageBox, set the desired properties, and call exec() to show the message. The simplest configuration is to set only the message text property. QMessageBox msgBox; msgBox. setText("The document has been modified."); msgBox.
Best way to do this is to subclass QMessageBox
, e.g.:
class MyMessageBox : public QMessageBox
{
MyMessageBox() //<-- default constructor
{
setWindowTitle("Default title goes here"); //QMessageBox function
}
};
Use MyMessageBox
everywhere in the code.
You could instead add a TARGET in the .pro file. e.g. add this line to the .pro file:
TARGET = MyApp
Thus "MyApp" will be applied both as the executable file name and also as default value for windowTitle of all QMessageBoxes in the entire project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With