How to include one widget in another?
-
I created two widget one by command another by Qt form designer. The code as shown below. When i execute two separates forms displays....What changes do i need to do, so that one form displays inside another form as single widget?
fileopen.cpp
@
fileopen::fileopen(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::fileopen),
m_layout( new QVBoxLayout() )
{QPushButton* add = new QPushButton("Add"); connect(add, SIGNAL(clicked()), this, SLOT(addRow()));
m_layout->addWidget(add);
m_layout->setAlignment(Qt::AlignTop);QWidget* w = new QWidget(); w->setLayout(m_layout);
w->show();
ui->setupUi(this);
}
@ -
I think you need:
@
this->setCentralWidget(w);- ui->setupUi(this);
- ui->setupUi(this->centralWidget());
}
@ -
[quote author="Franzk" date="1320225013"]I think you need:
@
this->setCentralWidget(w);- ui->setupUi(this);
- ui->setupUi(this->centralWidget());
}
@[/quote]hmmm...sorry got a compiler error saying that..:
error: invalid conversion from 'QWidget*' to 'QMainWindow*'
error: initializing argument 1 of 'void Ui_fileopen::setupUi(QMainWindow*)'both error message pointing ui->setupUi(this->centralWidget());
-
You need to set the parent argument to the widget you want have the new widget contained in. If you use a layout correctly, then that is what happens as well. In your current code, w has a layout, but is not in a layout.
-
Ah right, I think I misunderstood the issue.
-
Just as an extra remark, I think I would create a separate widget for the central area. It could depend on the type of application though.