[solved]QVBoxLayout spaces between widgets



  • Hello

    I have a problem in QVBoxLayout.
    i want to remove space between two widgets.
    here is my code

        QVBoxLayout *layout = new QVBoxLayout(this);
    
        QTextBrowser *browser1 = new QTextBrowser();
        layout->addWidget(browser1);
        QSizePolicy policy;
        policy.setVerticalStretch(1);
        policy.setHorizontalStretch(1);
        policy.setVerticalPolicy(QSizePolicy::Preferred);
        policy.setHorizontalPolicy(QSizePolicy::Preferred);
        browser1->setSizePolicy(policy);
    
        QTextBrowser *browser2 = new QTextBrowser();
        layout->addWidget(browser2);
        QSizePolicy policy1;
        policy1.setVerticalStretch(4);
        policy1.setVerticalPolicy(QSizePolicy::Preferred);
        policy1.setHorizontalPolicy(QSizePolicy::Preferred);
        browser2->setSizePolicy(policy1);
    

    people says about this method

    browser1->setContentsMargins(-1, 0, -1, -1)
    or
    layout ->setContentsMargins(-1, 0, -1, -1)
    but i have not result.

    please help


  • Lifetime Qt Champion

    Hi,

    layout->setSpacing(0);
    layout->setContentMargin(0, 0, 0, 0);
    

    should do the trick



  • @SGaist
    layout->setSpacing(0); was enought. thank you...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.