Important: Please read the Qt Code of Conduct -

QFrame Sizing

  • I have used QFrame and layouts to create a main window But the frames do not extend to the width/height of the mainwindow like in the image.

    How to make sure that the frame extends to the width of the mainwindow and also specify the height of a frame?

  • Lifetime Qt Champion

    If u used layouts, then it should follow main window?
    OR in what way does it not work?

    Main window is special, so normally u insert a Central Widget, give it layout
    then insert all widget there. (into layout of central)

  • @mrjj
    But If I use a single layout, how can I group some widgets in to horizontal layout and somw widgets to vertical layout

  • Lifetime Qt Champion


    well just like u did now?

    So you have
    Central widget ( just a dummy qwidget)
    Layout for central
    your master widget , (the one seen on picture)
    containing all your widget as seen on picture.

    If you need layout in layout, you can always
    insert Qwidget and use as place holder for other type of layout.

  • @mrjj

    Actually I have added widgets in different layouts and added these layouts in to different frames which I placed in the UI file. This might be the reason they are not extending to the end of the window. Any solution to set the frame size. (i have used only sizepolicy for each frame)

  • Lifetime Qt Champion

    It sounds like u just need one extra layout to follow main win but talking about
    layouts is near to impossible.
    Also if any of the QFrames are
    just free floating then it wont scale.

    You can set min and max sizes on QFrames to adjust how they scale/resize.

    I need your project if to look at it. it not feasible to talk about as I have no idea what u put where etc.

  • @mrjj

    Mainwindow.cpp file

    QHBoxLayout *upperBarLayout = new QHBoxLayout;
        QVBoxLayout *sideBarLayout = new QVBoxLayout;
        QGridLayout *centralLayout = new QGridLayout;
    QGridLayout *bottomLayout = new QGridLayout();
        ui->topframe->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        ui->sideframe->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    //center frame

    View the Mainwindo.UI

    The bottom frame is below the central frame. Hope this gives a better idea of my problem.

  • Lifetime Qt Champion


    so widgetF should follow main win. ?

    but it seems not all is inside widgetF .
    so ui->topframe is not inside Central ?

    Why didnt you make all in UI editor?
    That way u can see at once if working.

  • @mrjj

    Thanks!! I have solved my problem by removing the frames and putting only layouts. Initially, the main window loads as I want with some space for another widget. I load a widget to this space through a slot then the entire window gets distorted. How to get it back to the original look? Is there a repaint function?

  • Lifetime Qt Champion

    the layout will repaint them self if you add widgets.

    If it becomes "strange" when you insert, its most likely
    due to the layout altering the layout.'
    Layout alter and controls the size of widgets so it might be some
    side effect of you inserting.

Log in to reply