PDA

View Full Version : how to insert one widget between another two widgets ina a list of widgets)



pakine
18th August 2010, 17:21
hi, i have a problem that i can't solve for the moment.
I have a list where i load a list of messages, each message is displayed in a widget panel.

i'm trying to perform go up & down actions with a up & down buttons and i don´t know how to remove a widget and insert it again one position before.

could anyone help me??

here there are some code:




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

//this code is to remove panels that they already are in the list
QLayoutItem *child = 0;
while ((child = layout->takeAt(0)) != 0)
{
QWidget *widget = child->widget();
if (widget) widget->deleteLater();
delete child;
}

// with this code i create the panels
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);

}
it++;
}

((QVBoxLayout *)layout)->addStretch ();



but afterthat in other function i need to insert panels between some of them,
and i just have found this method to insert widgets: layout->addWidget (panel);

can i perform what i want?

thanks anyway

Lykurg
19th August 2010, 00:42
see QBoxLayout::insertWidget() and you might reconsider using QListWidget with custom widgets. It should be easier and for a short list its ok.

pakine
20th August 2010, 13:20
ok i got it, thank you very much