Important: Please read the Qt Code of Conduct -

Layout issue in the window.

  • Hi all,

    I have a problem in making layout to my MainWindow. Mainwinbdow is having manu bar , tool bar on the top and the rest space has to be occupied by three things. I planned to keep fixed postion tabwidget on left side, next to it I need to show multiple docks in using grid layout and the property dock widget at the right side. I added a image so that to get good imagination on my problem.Can some please the best way to make a suitable layout. I tried HBoxlayout, VBoxLayout,GridLAyout. Might be am on wrong trck..Someone please suggest to do this.
    [ image.PNG?dl=0 ](link url)


  • Hi there,

    Instead of a QTabWidget on the left side, you could use a QListView linked to a QStackedLayout
    Not sure this is what you need, but you can achieve this kind of interface:

    Basically you can hide/show multiple QWidget on the QStackLayout depending on the selection of the QListView.
    Good luck!

  • Hi Mr.Maximus,

    I need a Tabwidget with two tabs, each tab holds different controls. Could you please have a look on my link.'SO that you will get an idea.
    thanks for your advice.
    Please have look on the image attached here.


  • Thank you for the picture.

    You could have a ListView on the left replacing the TabWidget, then 2 QStackWidget on the right.
    Would be best if you could show the interaction with the 3 UI at the bottom so we can understand better what you need. Hand written UI works fine for saving time :)

  • Thank you Mr. Maximus,

    In the moment I don't have full stuff to show. But I can explain the whole thing for better understanding of my problem. But approximately I will going to some stuff some like this. Please have a look on controls and visualization window. In my case I also will be having another dock on Right side. Thid right side dock will also make communication Visualization screen,

    Might after end of the code.It might look this stuff

    thank in advance,

  • Here is part of my code:
    Qwidget *window = new Qwidget;
    creat Actions();

    Q**** mainlayout = new Q***; ////////////////////////how to give the layout like in the linkof the above post
    mainlayout->addwidget/layout (tabwidget goes here);

    void mainwindow:: createmenubar()
    //menu stuff file edit blah etc
    void mainwindow::createtoolbar()
    fonttoolbar->addaction***** blah
    void mainwindow::create_tabW_widget_container()
    void mainwindow::createdocks_for_opengl()
    Qgridlayout *gridodopengldocks = new QGridlayout;
    Qdockwidget 'dock = new Qdockwidget;
    QOpenGLWidget *glwidget = new QopenglWidget;

    void mainwindow::createporperty()
    Qdockwidget 'prop_ock = new Qdockwidget;
    property_dock->setpositon (Right..)


  • Oh I see now.

    You only need a QHorizontalLayout a the bottom for your 3 QWidgets

    So basically:

    1. Set Main Layout to a Vertical Layout
    2. Insert Menu Bar, Tool, bar, specifiy a maximum height so it doesn't take too much
    3. Create a Horizontal Layout, insert your 3 QWidget there
    4. Insert the Horizontal Layout(3) in the Vertical Layout

    You can do all this in the Designer just for testing
    Good luck,

  • This post is deleted!

  • Hi Maximus ,

    I was trying this as you told.But it is giving me the crash. I don't know Where I did mistake.
    It is giving error :: QLayout: Cannot add a null layout to QHBoxLayout/

    And here is code clip..

    MainWindow:: MainWindow()
        QWidget *window = new QWidget();
        QHBoxLayout *HLayout = new QHBoxLayout;
        HLayout->addLayout(tabbox );
        QVBoxLayout *mainLayout = new QVBoxLayout;
        QString message = tr("A context menu is available by right-clicking");
        setMinimumSize(160, 160);
        resize(1200, 800);
    void MainWindow :: createPropertyDock()
       QHBoxLayout *docks =new QHBoxLayout;
        QDockWidget *dock = new QDockWidget(tr("Properties"), this);
        dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
        addDockWidget(Qt::RightDockWidgetArea, dock);
     void MainWindow :: createtabwidget()
        QHBoxLayout *tabbox = new QHBoxLayout;
        QTabWidget *tabWidget = new QTabWidget;
        tabWidget->setSizePolicy(QSizePolicy ::Fixed , QSizePolicy ::Fixed);
    void MainWindow::createDockWidget()
       QGridLayout *grid = new QGridLayout;
        QDockWidget *dw = new QDockWidget;
            dw->setWidget(new QOpenGLWidget);

    thnaks in advance ,

    [edit: Added missing coding tags ``` SGaist]

  • Lifetime Qt Champion

    @N.Sumi said:
    Hi, just a question.
    void MainWindow :: createtabwidget()
    you create the local variable:
    QHBoxLayout *tabbox = new QHBoxLayout;
    and in
    MainWindow:: MainWindow()
    Layout->addLayout(tabbox );

    If they are the same ?, then tabbox should live in MainWindow class and it should be
    tabbox = new QHBoxLayout;
    in createtabwidget()
    My guess is that you did declare them in .h but made a local var by accident. ?

  • Hi mrjj,

    you are right. They both are same. But I have changed them to as you said. But it's stilling not working. I dont know what the mistake am doing here.

  • Good way to find where it crash it put qDebug message here and there, or use the debugger.

  • Lifetime Qt Champion


    If it crashes, a simple run through the debugger will tell you where exactly it misbehave

Log in to reply