[SOLVED]Space between widgets ( added to QSplitter )



  • I have a QScrollArea and a QtreeWidget added to a QSplitter:

    @QSplitter* someSplitter = new QSplitter( parent );
    someSplitter->addWidget( firstWidget );
    someSplitter->addWidget( secondWidget );

    //I want the space between my widgets to very small
    QSplitterHandle *handle = someSplitter->handle(1);
    handle->setMaximumWidth( 1 );
    //indeed the splitter handle will have width = 1 but the space between widgets is still there, how can I get rid of it?

    @
    Thanks!



  • Did you set the contents margins of the layouts of firstWidget/secondWidget (see "QLayout::setContentsMargins()":http://doc.qt.nokia.com/4.7/qlayout.html#setContentsMargins and "QWidget::setContentsMargins()":http://doc.qt.nokia.com/4.7/qwidget.html#setContentsMargins).



  • did that too, not working, I implemented a small example that reproduces the behaviour:

    @#include<QApplication>
    #include<QSplitter>

    int main( int argc, char* argv[])
    {
    QApplication app( argc, argv );

    QSplitter* splitter = new QSplitter;
    splitter->setFixedSize( 300, 300 );
    QWidget* widget1 = new QWidget( splitter );
    QWidget* widget2 = new QWidget( splitter );
    widget1->setStyleSheet( "QWidget{ background: red}" );
    widget2->setStyleSheet( "QWidget{ background: blue}" );
    
    widget1->setContentsMargins( 0,0,0,0 );
    widget2->setContentsMargins( 0,0,0,0 );
    
    splitter->addWidget( widget1 );
    splitter->addWidget( widget2 );
    
    //I want that the space between widgets to be only a line
    QSplitterHandle *handle = splitter->handle(1);
    handle->setFixedWidth( 1 );
    
    splitter->show();
    
    return app.exec(&#41;;
    

    }@



  • Use

    @
    splitter->setHandleWidth(1);
    @

    This sets the width of all handles of the splitter to width 1.



  • worked, thanks


Log in to reply
 

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