Qt World Summit: Submit your Presentation

C++ and Layout

  • Hey guys,
    probably a pretty easy to answer question, but i cant find an answer to it.

    How can i create a Layout that has a small List of Items on the left side and right next to it alot of icons depending on which item on the left side i have selected.

    I tried using a QGridLayout and adding 2 QListView Widgets to it.
    WidgetA one showed me my categories, but took more than half the screen.
    WidgetB wasnt filled by me yet, but it was super small on the right side of the screen because WidgetA one was dominating.

    When i switched both of them in my QGridLayout, WidgetB was now the dominating and WidgetA the super small one.

    Example code:

    QGridLayout * layout = new QGridLayout();
    layout->addWidget(_categoryWidget, 0, 0, 1, 1);
    layout->addWidget(_iconWidget, 0, 1, 1, 2);

    Category / IconWidget is:

    _listWidget = new QListWidget;
    QVBoxLayout * layout = new QVBoxLayout;

  • Lifetime Qt Champion

    You can use layoutStretch to tell how you want space divided
    alt text

  • I'm not using any designer.
    It's all written in C++.

    Here is my current result:


    I've added buttons to my layout for each column.
    _layout->addWidget(new QPushButton("A"), 0, 0, 1, 1);
    _layout->addWidget(new QPushButton("B"), 0, 1, 1, 1);
    _layout->addWidget(new QPushButton("C"), 0, 2, 1, 1);

    Then i have:

    _layout->addWidget(_categoryWidget->getUI(), 1, 0, 1, 1);
    _layout->addWidget(_assetWidget->getUI(), 1, 1, 1, 2);

    And my Widgets actually are just new QListView Widgets and set as a Widget in a seperate QGridLayout which is added as "CategoryWidget->getUI()"

    How can i decrease the size of column a to be the same size as my ListView in column A ? Is there any automatic way to do it ?

  • Lifetime Qt Champion

    Designer or code matters not. Designer creates c++ code.
    you can still use LayoutStretch.
    Or set Min/Max sizes on the widgets.
    alt text

  • Thanks for your help.
    I've figured it out :)

    Had to change the size policy of my ListViews and also set the maximum width.

    Thanks for your help tho :)

  • Lifetime Qt Champion

    please mark as solved.

Log in to reply