Question

I am a student programmer using Qt to build a GUI interface fro my company. I am currently building a reader table that reads in data and separates it appropriately based on file type. Anywho; when a certain file extension is selected I have a Message box display for selecting what type of data is in this file. Currently the message box shows all the buttons stacked from left to right and it looks kinda dumb. I want them to either stack from top to bottom of even better stack 2x2. I have been looking through QMessageBox documentation and cant seem to find a method to do this. I know that one must exist it seems i just need some help finding it. Currently my cod for this message box looks like this;

            QMessageBox templateSelectorWindow;
            QPushButton * pressureBC =templateSelectorWindow.addButton("Pressure Boundry Condition", QMessageBox::AcceptRole);
            QPushButton * flowBC = templateSelectorWindow.addButton("Flow Boundry Condition", QMessageBox::AcceptRole);
            QPushButton * massFlowBC = templateSelectorWindow.addButton("Mass Flow Boundry Condition", QMessageBox::AcceptRole);
            QPushButton * thermalWallBC = templateSelectorWindow.addButton("Thermal Wall Boundry Condition", QMessageBox::AcceptRole);
            QPushButton * cancelButton = overwriteWarning.addButton("Cancel", QMessageBox::RejectRole);
            templateSelectorWindow.setWindowTitle("Input File Type");
            templateSelectorWindow.setText("Input Files Require You Select The Input File Type:");
            templateSelectorWindow.setInformativeText("Please select the the input type from the following");
            templateSelectorWindow.exec();

currently this windows looks like this: enter image description here

so know you can see why I'd like to change the layout here. Thanks for reading my post! Thanks in advance for any help you can contribute to overcoming this challenge.

Was it helpful?

Solution

To achieve that you will have to create your own dialog extending QDialog, use a QDialogButtonBox for your buttons layout and add it as a widget to your custom QDialog.

Using QmessageBox won't allow you to change the buttons orientation. And if you want a 2x2 display you will have to play a bit more with a combination of layouts (with two QDialogButtonBox).

OTHER TIPS

Absolutely you need a QDialog not QMessageBox, because you can not control the layout of the QMessageBox.

Using the QDialog and using grid layout as you need grid of 2X2 you can meet the solution. On top of that you can get every functionality that a QMessageBox can have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top