Results 1 to 4 of 4

Thread: problems with layout - (stretch)

  1. #1
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default problems with layout - (stretch)

    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.

    Qt Code:
    1. QWidget *scrollWidget = ui.scrollTx;
    2. QVBoxLayout *layout = (QVBoxLayout*) scrollWidget->layout ();
    3.  
    4.  
    5. //Creo los nuevos paneles y los añado a la lista.
    6. for (it = m_cListaTx.begin (); it != m_cListaTx.end ();)
    7. {
    8. CArincMsgData *msg = *it;
    9. if (msg)
    10. {
    11. PanelTx *panel = new PanelTx (msg, *this, layout->widget());
    12. layout->addWidget (panel);
    13. }
    14. it++;
    15. }
    16. ((QVBoxLayout *)layout)->addStretch ();
    To copy to clipboard, switch view to plain text mode 
    when i addStretch, all the panels are displayed together with no space between them..



    and here is the code i have problems with

    Qt Code:
    1. QWidget *scrollWidget = ui.scrollTx;
    2. QVBoxLayout *layout = (QVBoxLayout *)scrollWidget->layout ();
    3.  
    4. int i;
    5. for (i = 0, it = m_cListaTx.begin(); it != m_cListaTx.end (); it++, i++)
    6. {
    7. //localizo el panel
    8. msg = *it;
    9. panel = m_cListaPanelsTx[msg->getLabel()];
    10. if( label == atoi(msg->getStrLabel().c_str ()) )
    11. {
    12. //when i locate the message i create as many parameter panel as it has
    13.  
    14. params = msg->getParametros ();
    15. for(int j = 0; j < params.size(); j++)
    16. {
    17. OutputDebugStringA ("voy a insertar un panel\n");
    18.  
    19. //create a panel
    20. PanelTxParams *panelParametro = new PanelTxParams (layout->widget(),params[j],msg->getStrLabel ());
    21.  
    22. layout->insertWidget(++i,panelParametro);
    23. }
    24. ......
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by pakine; 25th August 2010 at 11:53. Reason: more info

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: problems with layout - (stretch)

    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 :
    Qt Code:
    1. layout->setSpacing(0)
    To copy to clipboard, switch view to plain text mode 


    after the loop where you fill layout with parameters :
    Qt Code:
    1. layout->addSpacerItem( new QSpacerItem(50,15) ) ;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with layout - (stretch)

    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..

  4. #4
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems with layout - (stretch)

    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.

Similar Threads

  1. Problems with layout
    By franco.amato in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2010, 15:42
  2. QWidget layout problems
    By MarkoSan in forum Newbie
    Replies: 3
    Last Post: 12th January 2010, 10:23
  3. Problems with QMainWindow and layout
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2009, 22:49
  4. Qt layout space + stretch
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 20th December 2007, 15:53
  5. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.