Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What determines the default title for a QMessageBox?

Tags:

qt

qmessagebox

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?

like image 250
Pieter Avatar asked Apr 18 '11 18:04

Pieter


People also ask

How do you change the title of a QMessageBox?

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.

What is a QMessageBox?

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.

How to use QMessageBox in Qt?

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.


2 Answers

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.

like image 182
JamesWebbTelescopeAlien Avatar answered Oct 14 '22 22:10

JamesWebbTelescopeAlien


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.

like image 1
Lilla Eli Avatar answered Oct 14 '22 20:10

Lilla Eli