2012-03-26 131 views
1

我是一位使用Qt为我的公司构建GUI界面的学生程序员。我目前正在构建一个阅读器表格,该表格读取数据并根据文件类型对其进行适当的分离。 Anywho;当选择某个文件扩展名时,我有一个消息框显示来选择该文件中的数据类型。目前消息框显示了从左到右堆叠的所有按钮,看起来有点笨。我希望他们能够从顶部到底部堆栈2x2。我一直在寻找QMessageBox documentation,似乎找不到一种方法来做到这一点。我知道一个人必须存在似乎我只是需要一些帮助找到它。目前我的这个消息框的鳕鱼看起来像这样;QMessageBox;按钮布局

  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(); 

目前这个窗口看起来是这样的: enter image description here

所以知道你可以看到为什么我想在这里改变布局。感谢您阅读我的文章!预先感谢您为克服这一挑战做出的贡献。

回答

8

为了实现这一点,您将不得不创建自己的对话框来扩展QDialog,使用QDialogButtonBox作为按钮布局,并将其作为小部件添加到您的自定义QDialog中。

使用QmessageBox不会允许您更改按钮方向。如果你想要一个2x2显示器,你将不得不多玩layouts(带有两个QDialogBu​​ttonBox)的组合。

6

绝对需要QDialog而不是QMessageBox,因为您无法控制QMessageBox的布局。

使用QDialog并使用网格布局,因为您需要2X2的网格,您可以满足该解决方案。 最重要的是,您可以获得QMessageBox可以拥有的所有功能。