1

我是一名学生程序员,使用 Qt 为我的公司构建 GUI 界面。我目前正在构建一个读取器表,它读取数据并根据文件类型适当地分离它。任何人;when a certain file extension is selected I have a Message box display for selecting what type of data is in this file. 目前,消息框显示了从左到右堆叠的所有按钮,看起来有点愚蠢。我希望他们从上到下堆叠更好的 2x2 堆叠。我一直在查看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();

目前这个窗口看起来像这样: 在此处输入图像描述

所以知道你可以明白为什么我想在这里改变布局。感谢您阅读我的帖子!提前感谢您为克服这一挑战提供的任何帮助。

4

3 回答 3

8

要实现这一点,您必须创建自己的扩展 QDialog 的对话框,使用QDialogBu​​ttonBox进行按钮布局,并将其作为小部件添加到自定义 QDialog。

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

于 2012-03-26T17:00:12.640 回答
6

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

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

于 2012-03-26T17:37:14.510 回答
0

可能最好按照建议将 QDialog 子类化,但如果您愿意,可以更改 QMessageBox 中的按钮方向。尝试:

msgBox = QMessageBox()
buttonBox = msgBox.findChild(QDialogButtonBox)
buttonBox.setOrientation(Qt.Vertical)
于 2021-10-22T10:18:00.577 回答