How to resize QMessageBox
-
for some reason i could see them
-
I wanted to have a fixed width QMessageBox back in the 4.x days of Qt but I couldn't do this without subclassing QMessageBox and updating the width in the resizeEvent():
void TMessageBox::resizeEvent(QResizeEvent *Event) { QMessageBox::resizeEvent(Event); this->setFixedWidth(d_FixedWidth); } // where 'd_FixedWidth' is the width in pixels.
I still use this and it works fine (currently Qt 5.6.0) but I probably should revisit this 'hack'. My goal was to have better control over the message box width and to have something that had a (somewhat) unique visual style.
-
@Wieland I agree this is bad in general but, sometimes, having an application specific theme is a desirable goal and can be positive.
For example I was working with one software where everything (dialog's, windows, background images, and even the window controls) where unique to the application. It can give it a certain feel and appeal which didn't seem too bad. It can be horrible if taken too far but if done properly it can be quite decent. Even Qt supports this idea somewhat (you can use the 'Fusion' theme in your Qt application if you are so inclined across all OS's).
Using a modified QMessageBox should not be a big deal provided it works. I would never have done this if the Windows version of the QMessageBox was not so annoyingly ugly.
-
@kshegunov The width of the QMessageBox is fixed (not the height). If the text doesn't fit it wraps to the next line and the QMessageBox grows in height. If the font is set so big that it cannot be displayed then there are other issues - lol.
I agree stuff like this should be avoided but in this case it is a low risk. I didn't start this thread so I assume others don't like the ugly QMessageBox dialogs on Windows either.
-
@alper39 said in How to resize QMessageBox:
Hi Michael,
I put blank on the left and right but no change in this situation.On Windows this works using simple blanks:
QMessageBox::critical(nullptr, qa("title"), qa(" text "));
If it does not work on other systems I would consider it to be a bug.
-Michael. -
@m-sue
Thank you Michael,
You said true.QMessageBox::critical(this, "Warning", " Login Failed ");
Firstly, I put blank on the left and right "Warning" but no change in this situation.
Later, I put blank on the left and right " Login Failed "
It is ok