PDA

View Full Version : How to set minimum width of a dialog that derived from QMessageBox (All I try failed)



royt
12th March 2012, 16:52
I have a class drived from QMessageBox, and the size of the dialog is set by default, I want it to be wider and have a better look (less word wrap). Of course, setMinimumWidth() or setFixedSize() don't work, the size is automatically computed by QMessageBox. I searched the web, someone said that overwrite showEvent() or resizeEvent() could do, I've tried but it had no effect, my QT version is 4.7, maybe that method only works with older Qt. I also found an ugly way to set the minimum size, that is, adding many spaces to window title, at last I find it's not a workaround, since there is always three dot "..." at the end of the title bar, not user friendly. Our project had used a lot of such derived message box, it's not a good idea to write a new one, I want to know is there any other way to change the size?

high_flyer
13th March 2012, 10:25
If you are under windows, then you can remove the Qt::MSWindowsFixedSizeDialogHint from the constructor which is set by default.
(I am not 100% this actually limits the dialog size or is it only a style used usually for fixed sized dialogs - but you can try it)
I don't have a way of testing this at the moment but my guess is that the QMessageBox is setting its size policy to fixed by default.
Try setting the size policy to something else and then set a new geometry/size.

I want it to be wider and have a better look (less word wrap).
What you mean by "less"?
It will either word wrap or it wont - how can it be less or more?
You might want to have a look at QMessageBox::setTextFormat()