PDA

View Full Version : how to add 2 different types of widget to a QScrollArea



pakine
25th August 2010, 15:36
I have this problem:
I have 2 types of panels that i need to add or insert inside a qscrollarea:
PanelTx (CArincMsgData *msg, ListaMensajes &listaMensajes, QWidget *parent = 0);
PanelTxParams(QWidget *parent, CArincParam * param, std::string label);

Two types are almost identical, they have the same dimension, cause the second one is a copy of the first one but with other label and fields.

my problem is that when i insert or add to the qscrollarea layout the first type of panel there is no problem, but with the second one i have problems at the time of display them.

i ahve this function to load the panels at the beginning or the program, and it works perfectly.


....
QWidget *scrollWidget = ui.scrollTx;
QVBoxLayout *layout = (QVBoxLayout*) scrollWidget->layout ();

for (it = m_cListaTx.begin (); it != m_cListaTx.end ();)
{
CArincMsgData *msg = *it;
if (msg)
{
PanelTx *panel = new PanelTx (msg, *this, layout->widget ());
layout->addWidget (panel);
m_cListaPanelsTx[msg->getLabel ()] = panel; // almaceno el panelTx en la lista(map)

if(!msg->isEnabledTx() && ui.btnEnableAllTx->isChecked()) //aqui compruebo si hay alguno q no esta habilitado
ui.btnEnableAllTx->setChecked(false);
}
it++;
}
((QVBoxLayout *)layout)->addStretch ();
....


but i have this other function



....
QWidget *scrollWidget = ui.scrollTx;
QVBoxLayout *layout = (QVBoxLayout*) scrollWidget->layout ();
for(int j = 0; j < params.size(); j++)
{

PanelTx *panelParametro = new PanelTx (msg, *this, layout->widget ());
layout->insertWidget(++i,panelParametro);
}
...

with this function i insert int he position that i need (between other panels) as many panels as parameters has the message.

if the panel is this type: PanelTx, the same type as the panels loaded at the first function, there is no problem and they are inserted.

but if i use this other panel..



....
QWidget *scrollWidget = ui.scrollTx;
QVBoxLayout *layout = (QVBoxLayout*) scrollWidget->layout ();
for(int j = 0; j < params.size(); j++)
{

PanelTxParams *panelParametro = new PanelTxParams (layout->widget(),params[j],msg->getStrLabel ());
layout->insertWidget(++i,panelParametro);
}
...


i have problems with displaying them. They dont appear but, some elements inside the layout are created (as many as panels i insert). i know that using layout->count()
And some space is used at the end of the layout, but they aren't displayed.

does anyone know the reason, or the solution?

thanks a lot