sergey_85
16th December 2009, 19: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!
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!