You can create your layout with the QWidget as parent (and the widgets added to layout will be re-parented to the MainWindow/Widget), like this:
MainWindow w;
QLabel label
= new QLabel;
//this will have w as a parent after it's added to the v_layout //add more widgets to layout
//...
v_layout->addWidget(label);
//...
w.show(); //you need to show just w
MainWindow w;
QLabel label = new QLabel; //this will have w as a parent after it's added to the v_layout
//add more widgets to layout
//...
QVBoxLayout *v_layout = new QVBoxLayout(&w);
v_layout->addWidget(label);
//...
w.show(); //you need to show just w
To copy to clipboard, switch view to plain text mode
LE: the code above will work if you use a QWidget as the window (sorry)
if you use the QMainWindow or derived from it, you will need to parent the layout to a "container" QWidget and then add that QWidget as a centralWidget of your QMainWindow object, something like:
MainWindow w;
QLabel label
= new QLabel;
//this will have w as a parent after it's added to the v_layout //add more widgets to layout
//...
v_layout->addWidget(label);
//...
w.setCentralWidget(container);
w.show(); //you need to show just w
MainWindow w;
QWidget *container = new QWidget;
QLabel label = new QLabel; //this will have w as a parent after it's added to the v_layout
//add more widgets to layout
//...
QVBoxLayout *v_layout = new QVBoxLayout(container);
v_layout->addWidget(label);
//...
w.setCentralWidget(container);
w.show(); //you need to show just w
To copy to clipboard, switch view to plain text mode
Bookmarks