2013-12-17 26 views
0

我有一個QDialog在設計器中創建了一個QFrame testFrame,我已經添加了一個QHBoxLayout,並且在整個事情創建並顯示之後我試圖以編程方式創建一個以QFrame作爲父項的新小部件。無論我嘗試新的部件將不會顯示:Qt 3 - 將一個小部件添加到已經存在的小部件及其佈局

末的init()方法:

QBoxLayout *testFrameLayout = new QHBoxLayout(this->testFrame); //QT3 docs use QBoxLayout pointer when creating QHBoxLayout 

期間發生的事件(例如,一個單獨的按鈕被按下)

testButton = new QPushButton(this->testFrame); 
testButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false); 
testButton->setMaximumWidth(50); 
testButton->setMaximumHeight(50); 
testButton->setMinimumWidth(50); 
testButton->setMinimumHeight(50); 

testFrameLayout->addWidget(testButton); 

我得到這種行爲與不同的小部件,容器類(例如QGrid,我不必管理任何佈局的東西),調用update()/ repaint()(在testFrame,testButton,對話框本身)等等,無論我嘗試它的工作時在init()中完成,但如果在顯示對話框後完成,則不會。我必須錯過一些東西,所以任何幫助將不勝感激!

注意:我正在開發一個使用Qt 3的非常大的項目,因此解決方案必須與此版本兼容。

+0

「QT3」,真的嗎? :-) – lpapp

+0

不幸的是,現在:) – Rajveer

回答

0

末調用

testButton->show(); 

解決了這個問題。由於在框架上使用adjustSize()而沒有在實際按鈕上使用show()會使框架消失,所以我認爲可能會隱藏小部件,直到在像這樣添加時明確顯示。

0

下面是一個對話框,一些工作代碼在我QT3應用:

QVBoxLayout *vb = new QVBoxLayout(this, 5, 5); 
// ... 
QHBoxLayout *askline = new QHBoxLayout(vb, 10); 
QPushButton *ok  = new QPushButton(tr("OK"), this); 
QPushButton *cancel = new QPushButton(tr("Cancel"), this); 
askline->addWidget(ok); 
askline->addWidget(cancel); 
adjustSize(); 
// ... 

我覺得你的問題是,佈局還沒有分配的任何空間,爲您QPushButton,並在需要adjustSize()

+0

感謝您的提示,但最終導致整個框架消失。然而,最後的工作是調用testButton-> show()。我的開發主管說他記得以前也有這個問題。 – Rajveer

相關問題