2012-03-26 181 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可以擁有的所有功能。