Creating a new widget and apply it on another widget
Hello everyone,
imagine that i have something like this in a class
and in one of the public functions i want to add other widgets like maybe a QPushButton and a QVBoxLayout. How can i do that?
For the QPushButton i tried it this way:
Code:
widget->layout()->addWidget(btn);
But the widget has currently no layout, so i cannot try it out...
Is it possible to do it this way, and how can i apply a layout to the widget?
Re: Creating a new widget and apply it on another widget
Write more code. You should use a name of class that have a widget. Where you use a code with QPushButton?
Re: Creating a new widget and apply it on another widget
Quote:
But the widget has currently no layout, so i cannot try it out...
It isn't magic, you have to set one: QWidget::setLayout()
Lots more in the trusty manual
Re: Creating a new widget and apply it on another widget
the widget has no layout, so probably your child widgets are manually managed for resize. For widgets without layouts, you should pass the parent widget pointer to the child widget's constructor
pushButton = new QPushButton("Hello",this);