initialize child widgets within parent?
Hi, i was wondering if it is possible to initalize a child widget within the parent?
I tried to add it in the constructor of the parent, but then the child widgets is not shown...
In this case i want to initialize fx1 in the constructor of floorBoard... this to keep clean main.
Code:
#include "stompBox.h"
#include "floorBoard.h"
int main(int argc, char *argv[])
{
floorBoard floor;
stompBox fx1(&floor);
fx1.setId(0);
fx1.setImage(":/images/fx1.png");
fx1.setPos(floor.getPos(0));
fx1_comboBox->addItem( "Test 1" );
fx1_comboBox->addItem( "Test 2" );
fx1_comboBox->addItem( "Test 3" );
fx1_comboBox->setGeometry(8, 31, 79, 13);
fx1_comboBox->setEditable(false);
fx1_comboBox->setFont(font);
fx1_comboBox->setPalette(pal);
fx1_comboBox->setFrame(false);
customButton fx1_button
(false,
QPoint::QPoint(4,
110),
&fx1
);
QObject::connect(&fx1_button,
SIGNAL(valueChanged
(bool)),
&fx1_led, SLOT(setValue(bool)));
floor.show();
return app.exec();
};
Re: initialize child widgets within parent?
If stompBox is a widget, then it shouldn't be any problem. If it is a dialog, though, you'll have to explicitely call show() or exec() for it. But you can still do the initialisation in the parent -- that's what is usually done, anyway...
Re: initialize child widgets within parent?
It is a widget. But when I do so the widget isn't shown. And if I add .show() it just shown on initialization and disapears inmediatly after :confused: :crying:
Code:
#include "stompBox.h"
#include "floorBoard.h"
int main(int argc, char *argv[])
{
floorBoard floor;
floor.show();
return app.exec();
};
Code:
#include "floorBoard.h"
floorBoard
::floorboard((QWidget *parent, ...
){
...
stompBox fx1(this);
fx1.setId(0);
fx1.setImage(":/images/fx1.png");
fx1.setPos(this->getPos(0));
fx1_comboBox->addItem( "Test 1" );
fx1_comboBox->addItem( "Test 2" );
fx1_comboBox->addItem( "Test 3" );
fx1_comboBox->setGeometry(8, 31, 79, 13);
fx1_comboBox->setEditable(false);
fx1_comboBox->setFont(font);
fx1_comboBox->setPalette(pal);
fx1_comboBox->setFrame(false);
customButton fx1_button
(false,
QPoint::QPoint(4,
110),
&fx1
);
QObject::connect(&fx1_button,
SIGNAL(valueChanged
(bool)),
&fx1_led, SLOT(setValue(bool)));
};
Re: initialize child widgets within parent?
I think it should be something like
Code:
stompBox *fx1 = new stompBox(this);
fx1->setId(0);
fx1->setImage(":/images/fx1.png");
fx1->setPos(this->getPos(0));
Re: initialize child widgets within parent?
Both do the samething, I guess... But that ain't the problem. The widget just flashes 1 time on the screen on initialization and thats it.... :eek:
Re: initialize child widgets within parent?
Yes both do the samething but in your way of declaration the object is destroyed once the program is out of the constructor. Either you have to declare fx1,fx1_button..etc in your class declaration or use them the way you are using fx1_comboBox(as a pointer).
Re: initialize child widgets within parent?