2015-06-13 33 views

回答

2

當然,這很容易。您可以查看debug/release目錄下的ui_mainwindow.h。我更喜歡在QtDesigner中爲代碼設置小部件的佈局。這是這樣的:

//set layout programatically 
auto layout = new QHBoxLayout(ui->centralWidget()); 

//or if you have set horizontalLayout in Qt Designer 
auto layout = dynamic_cast<QHBoxLayout*>(ui->centralWidget->layout()); 

layout->addWidget(new QLabel("hello")); 
+0

嘿,這兩個似乎不工作,ui-> centralWidget沒有addWidget方法。 此外,第二行,給出了一個錯誤「預計(在dynamic_cast之後」,也一旦獲得佈局,如何向其添加小部件並導致centralWidget刷新? –

+0

現在應該可以正常工作了@AakashThakkar – Zen

+0

很棒!:D –

相關問題