简体   繁体   English

QMessageBox; 按钮布局

[英]QMessageBox; button layouts

I am a student programmer using Qt to build a GUI interface fro my company.我是一名学生程序员,使用 Qt 为我的公司构建 GUI 界面。 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.我希望它们从顶部到底部堆叠甚至更好的 2x2 堆叠。 I have been looking through QMessageBox documentation and cant seem to find a method to do this.我一直在查看QMessageBox 文档,但似乎找不到一种方法来做到这一点。 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:目前这个窗口看起来像这样:在此处输入图片说明

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.在此先感谢您为克服这一挑战提供的任何帮助。

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. 为了实现这一点,您将必须创建自己的扩展QDialog的对话框,对按钮布局使用QDialogBu​​ttonBox并将其作为小部件添加到自定义QDialog中。

Using QmessageBox won't allow you to change the buttons orientation. 使用QmessageBox不允许您更改按钮方向。 And if you want a 2x2 display you will have to play a bit more with a combination of layouts (with two QDialogButtonBox). 而且,如果您想要2x2的显示屏,则必须结合使用布局 (带有两个QDialogBu​​ttonBox)来播放更多内容。

Absolutely you need a QDialog not QMessageBox, because you can not control the layout of the QMessageBox. 绝对需要QDialog而不是QMessageBox,因为您无法控制QMessageBox的布局。

Using the QDialog and using grid layout as you need grid of 2X2 you can meet the solution. 使用QDialog并根据需要使用2X2网格的网格布局可以满足该解决方案。 On top of that you can get every functionality that a QMessageBox can have. 最重要的是,您可以获得QMessageBox可以具有的所有功能。

Probably best to subclass QDialog as suggested, but you can change the button orientation in QMessageBox if you wish.可能最好按照建议对 QDialog 进行子类化,但如果您愿意,您可以更改 QMessageBox 中的按钮方向。 Try:尝试:

msgBox = QMessageBox()
buttonBox = msgBox.findChild(QDialogButtonBox)
buttonBox.setOrientation(Qt.Vertical)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM