Layout tutorial wanted

  • Can anyone here recommend a clear and comprehensive tutorial on Qt Layouts ?
    I'm totally confused on this topic by reading always partial descriptions on single
    simple solutions but do not get the general philosophy behind the concepts.

  • (that is more for widget layouts, not QML but I guess you don't want to use QML for your layouts?)
    also there are many examples shipped with Qt Creator itself.

  • Yes, there is a lot to read about layouts. But maybe we can help you on the right track by assisting in making your specific dialog with layouts in it. You could make a picture of what you want and we can guide you through.

  • thank you for this suggestion, but i do not have a specific layout problem.
    In some way (trial & error) i fixed the most designs i needed so far.
    But i do not understand the systematic.
    Most confusing is sizepolicy-settings. When it affects childs and when it's own behavior in a parent. What is a sizehint and where it comes from ?
    When right-click on a widget in a Layout and select "size constraints",
    what does the set Minimum , set maximum do ? It does not set a size but seems to set "yes, use minimum size settings". And of course "prferred"
    "minimum expanding", "ignore" and so on. How are "size constraints" and
    "size policies" related to each other ?
    I'm already so messed up, that even my questions are stupid i think.

  • Everything you talk about is well explained in chapter 6 of this book:

    C++  GUI Programming with Qt 4 (2nd Edition) - The official C++/Qt book
    Author: Jasmin Blanchette and Mark Summerfield
    ISBN: 0132354160 / 978-0132354165

    i would recommend reading it.

  • I want to come back to Eddy's suggestion and ask a precise question.
    Assuming i have a QGroupBox with a QVBoxLayout with Topalignment
    and adding widgets to it. When the vertical space needed by these added widgets exceeds the height of the QGroupBox and i add even more widgets, the QGroupBox height grows and also its parent (centralwidget).
    How to implement a vertical scrollbar to the QGroupBox which gets visible
    when the required space by added new widgets exceeds the availbale height of this GroupBox ?. I do not want the growing QGroupBox makes its parent grow.

  • Lifetime Qt Champion


    You would need a "QScrollArea":http:// as "main widget" inside your QGroupBox

  • That is what i achieved so far. In some way it works.
    Seems i can not attach screenshots here, right ?
    but i'll try to explain question.
    How to get the widget containing all the Pushbuttons to fit
    entirely to the width of QGroupbox (parent) but has limited heigth and
    do not change parent size ?
    Why are the PushButtons also green. The stylesheet sets the background also for all childs ?

    @MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    QVBoxLayout *vb_1 = new QVBoxLayout;
    QGroupBox *gb_1 = new QGroupBox("gb_1-Title");
    gb_1->setStyleSheet("background: beige;");
    QVBoxLayout *vb_2 = new QVBoxLayout;
    for(int i=0;i<25;i++)
        QPushButton *pb_x = new QPushButton;
    QWidget *vb_2W = new QWidget;
    vb_2W->setStyleSheet("background: green;");
    QScrollArea *sa_1 = new QScrollArea(gb_1);


Log in to reply