Please nominate your Qt Champions for 2021!

Best way to use a QLayout For a QGLWidget which is next to a QToolBox?

  • With my current layout, I'm seeing the following:

    ! Layout)!

    The problem is that I'd like the QToolBox and its nested components to be larger in both height and width. Since the QToolBox encapsulates (currently - there will be more) a single QListView, I'm having some trouble figuring out the best way to do this.

    The ToolBox resides as a component within an InputFrame class, derived from QFrame, and is initialized within the following (inner) block, within the void MainWindow::init( void ) function

    (Note: I haven't set a QLayout for MainWindow - I tried that and Qt complained about there already being a default layout or something)

    @//! Initialize User Input
    mUserInput = new InputFrame( this );

        const int x = width - 400;
        const int y = ( height / 2 ) - 200;
        mUserInput->setGeometry( x, y, 300, 300 );
        mUserInput->setFrameShape( QFrame::StyledPanel );
        mUserInput->setFrameShadow( QFrame::Raised );


    When the InputFrame is initialized, the following ensues:

    @void InputFrame::init( void )
    QGridLayout* inputLayout = new QGridLayout( this );
    inputLayout->setObjectName( Layout::fetch( Layout::Input ) );

    mModules = new QToolBox( this );
    mGeometry = new QListView( this );
        QStringList strings( Glm::fetch( Glm::Geometry ) );
        addFunctionList( mGeometry, "Geometry", strings );
    mModules->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding );
    inputLayout->setSizeConstraint( QLayout::SetMaximumSize );
    inputLayout->addWidget( mModules );


    void InputFrame::addFunctionList( QListView* const& parent, const char* label, const QStringList& funcSigs )
    QItemDelegate* viewDelegate = new QItemDelegate( parent );
    QStringListModel* stringList = new ModuleStringList( parent );

    stringList->setStringList( funcSigs );
    parent->setItemDelegate( viewDelegate );
    parent->setModel( stringList );
    parent->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
    mModules->addItem( parent, label );


    After experimenting and reading the QLayout documentation - I feel like I'm missing something: the ToolBox is still small.

    I know this has to do with mUserInput->setGeometry(...), yet when I comment that call, the QToolBox and its child widget are thrown into the upper left corner of the screen and extremely small. Naturally I can specify larger dimensions, but if I understand correctly, this will render the layout settings void (i.e., useless given the fact that the ToolBox is hardly displayable at all) - correct?

    Anyway, I appreciate any clarifications/suggestions on this issue; thanks.

Log in to reply