PDA

View Full Version : problems with layout - (stretch)



pakine
25th August 2010, 11:48
Hi to all, i have one problem with a QVBoxLayout.
at first a list of messages are loaded into a QScrollArea. Those panels(messages) have a button to display its parameters in other panels below the message panel.
The problem is that when i try to insert the parameters penls below the message panel, they are displayed with space between them, and i dont know hot to display them together with no space.

here is the code to load the messages.It works well.




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


//Creo los nuevos paneles y los añado a la lista.
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 ();

when i addStretch, all the panels are displayed together with no space between them..



and here is the code i have problems with




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

int i;
for (i = 0, it = m_cListaTx.begin(); it != m_cListaTx.end (); it++, i++)
{
//localizo el panel
msg = *it;
panel = m_cListaPanelsTx[msg->getLabel()];
if( label == atoi(msg->getStrLabel().c_str ()) )
{
//when i locate the message i create as many parameter panel as it has

params = msg->getParametros ();
for(int j = 0; j < params.size(); j++)
{
OutputDebugStringA ("voy a insertar un panel\n");

//create a panel
PanelTxParams *panelParametro = new PanelTxParams (layout->widget(),params[j],msg->getStrLabel ());

layout->insertWidget(++i,panelParametro);
}
......


in this part im not using addstretch() cause i have used at messages loading. But if i use it the result is not the desirable.

when i insert the parameters panels they are not displayed together, but they are displayed with some lines of space between them.

other thing is that in other function i have to insert the same message panels and it works fine, but with those new panels (parameter panels) the result is different.

how can i get this working fine?

thanks a lot

totem
25th August 2010, 12:36
I'm not sure I clearly understood, but what about reducing the layout spacing and adding a spacer in the end :

after line 2 of the second code snippet :

layout->setSpacing(0)


after the loop where you fill layout with parameters :

layout->addSpacerItem( new QSpacerItem(50,15) ) ;

pakine
25th August 2010, 13:29
i have tried but nothing, so i ll try to explain it better :)
in the first function, loading the message panels, i add at the end ((QVBoxLayout *)layout)->addStretch (); to add a last element that fill all the remaining space. This element i think that stretch itself to fill the space. It's not necessary here layout->setSpacing(0);
Is i don't use ((QVBoxLayout *)layout)->addStretch () and all the panels i have loaded don´t fill the full area of scrollarea, they appear separated.

in the second function where i tried to display other kind of panels in the same QscrollArea, i have the problems. The main problem is that the new apnels are not displayed well.
For example if i load 4 panels that dont fill the full area and i push the button to load 2 parameters panels they are displayed separated.
And if i load as many parameters to fill the full area, (a scrollbar apeear) the parameter panels are not displayed, just a blank space.

if anyone could help me..

pakine
25th August 2010, 13:42
Another thing that i realized is that if i try this with the message panels that are load in the first function, there is no problem. everything is fine and i dont need to include more code or special instructions.

but with the new kind of panels (parameter panels) that have the same dimensions that the others, i have the problems to display them.