我是一名学生程序员,使用Qt为我的公司构建GUI界面。我目前正在构建一个读取器表,它可以读入数据,并根据文件类型适当地将其分离。Anywho;当选择某个文件扩展名时,我会显示一个消息框,用于选择该文件中的数据类型。目前,消息框显示从左到右堆叠的所有按钮,它看起来有点笨拙。我想让它们从上到下堆叠到更好的堆栈2x2。我一直在找QMessageBox documentation,但似乎找不到一个方法来做到这一点。我知道它肯定存在,似乎我只是需要一些帮助才能找到它。目前,我的消息框的cod如下所示;
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();目前,此窗口如下所示:

所以我知道你可以明白我为什么想要改变这里的布局。感谢你阅读我的帖子!提前感谢您为克服这一挑战所能提供的任何帮助。
发布于 2012-03-27 01:00:13
要实现这一点,您必须创建自己的对话框来扩展QDialog,使用按钮布局的QDialogButtonBox,并将其作为小部件添加到自定义QDialog中。
使用QmessageBox不允许您更改按钮的方向。如果你想要一台2x2的显示器,你必须使用layouts (带有两个QDialogButtonBox)的组合来播放更多的内容。
发布于 2012-03-27 01:37:15
你绝对需要一个QDialog而不是QMessageBox,因为你不能控制QMessageBox的布局。
使用QDialog和使用网格布局,因为你需要2X2的网格,你可以满足解决方案。最重要的是,您可以获得QMessageBox可以拥有的所有功能。
发布于 2021-10-22 10:18:01
最好按照建议将QDialog子类化,但如果愿意,您可以在QMessageBox中更改按钮方向。尝试:
msgBox = QMessageBox()
buttonBox = msgBox.findChild(QDialogButtonBox)
buttonBox.setOrientation(Qt.Vertical)https://stackoverflow.com/questions/9876283
复制相似问题