How to resize QMessageBox
-
wrote on 28 Sept 2016, 12:20 last edited by
Hello,
My issue is, size of the QMessageBox. I working Windows 7 no problem, I tried the same software with Ubuntu. window size of QMessageBox very small.
How can I adjust the size of the window?if (ud.checkUser(u)==false){ QMessageBox::critical(this, "DİKKAT", "Giriş Başarısız"); ui->pLineEditAccountName->clear(); ui->pLineEditAccountPassword->clear(); } else{
-
wrote on 28 Sept 2016, 12:26 last edited by
Images upload in this forum does not work I'm afraid you have to use an external uploader if you want us to see images.
The first thing that tingles my ear is non-ascii characters in a literal.
Could you try and replace "DİKKAT" with "Warning" and "Giriş Başarısız" with "Login Failed" and see if the size is correct?
-
wrote on 28 Sept 2016, 12:52 last edited by alper39
I tried and replaced but no change size of QmessageBox
-
-
wrote on 28 Sept 2016, 13:36 last edited by
Hi,
you can pad the text in the body of the message box with blanks on the left and right to not get "Dİ..." in the title.
-Michael. -
wrote on 28 Sept 2016, 14:41 last edited by
Hi Michael,
I put blank on the left and right but no change in this situation. -
QMessageBox messageBox(icon, title, text, QMessageBox::Ok, parent); messageBox.setMinimumSize(200, 0); if (messageBox.exec() == QMessageBox::Ok) { // Ok clicked }
-
wrote on 28 Sept 2016, 18:45 last edited by Rondog
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.
-
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.
wrote on 28 Sept 2016, 19:09 last edited by@Rondog I can't tell you how much I hate it when applications do that. As soon as someone uses a different font for the desktop theme than you the UI is broken.
-
wrote on 28 Sept 2016, 20:22 last edited by
@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.
-
@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.
He was referring to the fixed size of the dialog. It may very well happen (and it does) that the contents don't fit in the fixed width if the font is changed from the default.
-
wrote on 28 Sept 2016, 21:29 last edited by
@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.
-
wrote on 29 Sept 2016, 07:47 last edited by
@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. -
wrote on 29 Sept 2016, 08:49 last edited by A Former User
1/14