Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Center Text and Buttons in QMessageBox
retro_code last edited by
I'm fairly new using the QMessageBox class and have a question about how to align the text and buttons. I'm using the following code to create a message box and would like the text and box to be centered but when the box is created the text and button are displayed on the right-hand side of the box. I added the html center code but that didn't help with the text. Not sure what to do about the button. Any ideas? Maybe I shouldn't be using QMessageBox? I've searched through the QMessageBox class description and can't find anything on alignment.
@ //SHOW POP-UP WHEN SAVE COMPLETE
msgBox.setText("<center>Machine Configuration Saved</center>");
mohsen last edited by
@msgBox.setText("<p align='center'>First Line<br>"
goetz last edited by
Wether the buttons are centered is determined from the current style and is therefore platform dependend.
The text can be centered as shown by mohsen.
The icon is on the left side and has always reserved some space so the text is not completely aligned in the center as there's some phantom icon on the left (that may be changed by explicitly setting a 0x0 size icon, I did not test it).
So, in your case, I would go with a handcrafted message box (use designer!) with a label for the title, another label for the text and the buttons in a layout.