Function returning a QHBoxLayout
Hi, I want to do the following dialog:
http://img825.imageshack.us/img825/9126/schermata3v.png
now I have done a function which create an entry item, but I don't know how return "widget" or "layout" to allow to add them to a QGridLayut...
Code:
??? GestioneClienteDialog::creaItemCliente(Domain::Persona c)
{
??? widget = new ???; // widget or layout? what type? and how?
piva->setVisible(false);
piva->setText(c.piva());
ragionesociale->setText(c.ragionesociale());
cognome->setText(c.cognome());
nome->setText(c.nome());
indirizzo->setText(c.indirizzo());
citta->setText(c.citta());
boxDati->addWidget(cognome);
boxDati->addWidget(nome);
boxDati->addWidget(indirizzo);
boxDati->addWidget(citta);
boxContenitore->addWidget(ragionesociale);
boxContenitore->addLayout(boxDati);
boxEsterno->addWidget(radio);
boxEsterno->addLayout(boxContenitore);
widget->addWHAT(boxEsterno);
return widget;
}
Thank you...
Re: Function returning a QHBoxLayout
It depends on how you want use it, but normally a widget is a good choice:
Code:
QWidget* GestioneClienteDialog
::creaItemCliente(Domain
::Persona c
) {
//your code like
widget->setLayout(boxEsterno)
return widget;
Make sure that the receiver sets a valid parent for the widget.
Re: Function returning a QHBoxLayout
Hi aomegax, I think all depends of what you wish to do with the returned type. If you are going to used as a regular QWidget and add it to another Layout (for example, QHBoxLayout or QVBoxLayout, etc), then of course you should return a QWidget. But, if you wish to use the returned type as a container of QWidgets, or you are going to add more elements after call creaItemCliente; would be better to use a Layout as the returned type.
It's also important to note, the Parent-Child relationship between the components. Remember that if you call setLayout on a QWidget, all the components that you added to the QWidget via the QLayout, will be childs of the QWidget, not the QLayout.
So, it would be thoughtful if you have into account both of the recommendation I gave you.
I Hope this answers your question.
Re: Function returning a QHBoxLayout
Hi, thanks everybody to help me...
I have used both your informations...
At the end I have used layout because I must add them to a gridLayout...
now only one question...If I do:
Code:
while (grid->layout()->count() > 0)
{
if (l->layout())
{
delete l->layout();
}
delete l;
}
why the items added before isn't deleted? how can I do to clear gridLayout from all the layouts which I add in a first moment?
however thank you!
Re: Function returning a QHBoxLayout
Re: Function returning a QHBoxLayout