PDA

View Full Version : Add one layout to another, peraint problem



sergey_85
16th December 2009, 20:53
Hi!

History of my question: I have some widget, it's created in QtDesigner. Widget has some controls and LAYOUT (FormLayuot for example).
Next, my app. load this widget from ui file, and replace default layout(added in QtDesigner) to my new.

Qt code of app.

//load widget from ui file, it has default layout, which added in QtDesigner
QFormBuilder builder;
QFile file("c:/wgt.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = builder.load(&file, 0);
file.close();

//save old layout
QLayout *oldLayout = myWidget->layout();

//add new grid-layout and insert old layout to new
QGridLayout *newLayout = new QGridLayout();

//add toolbar & menu bar to new grid-layout
QMenuBar *menuBar = new QMenuBar(myWidget);
QMenu *menuFile = new QMenu(tr("File"));
menuBar->addMenu(menuFile);
newLayout->setMenuBar(menuBar);

QToolBar *toolBar = new QToolBar(myWidget);
toolBar->addAction("dsd",0,"");
newLayout->addWidget(toolBar,0,0);

//insert old layout to new!
newLayout->addLayout(oldLayout,1,0);
myWidget->setLayout(newLayout);

//this->ui.mdiArea->addSubWindow(myWidget);
myWidget->show();



But after execute it has bug!

high_flyer
17th December 2009, 10:24
What happens if you swap the layout adding?:


//insert old layout to new!
myWidget->setLayout(newLayout);
newLayout->addLayout(oldLayout,1,0);

sergey_85
17th December 2009, 12:19
see attached image

sergey_85
17th December 2009, 19:06
no changes then I replace code