How to add a layout to QWidget using designer?



  • Hi all! I came back to Qt Creator after 6 months break and I forgot the most important basics of Qt Designer. I need to add a layout to QWidget tab object so its contents will fill the whole tab at all times. Here is an image that explains what I try to achieve.
    http://imgur.com/Tz9sUYx



  • Hi @Tapsa !

    It seems that your "map_layout" is not included inside your "tab_research". No ?

    If i understand what you need, I'm doing like this :

    .

    //Create the QTabWidget
    QTabWidget m_tabWid = new QTabWidget(this);
    
    //Create tabs
    QWidget m_tab1 = new QWidget;
    
    //Create a boxlayout (vertical here)
    QVBoxLayout vbox = new QVBoxLayout;
    
    //Set the layout for your tab
    m_tab1->setLayout(vbox);
    
    //If you want to add widgets into your tab1
    vbox->addWidget();
    
    //Add tabs to the QTabWidget
    m_tabWid->addTab(m_tab1, "Settings");
    

    .

    QTabWidget>>layout>>tabs>>otherobjects

    Hope I understood what you actually need. It is without Designer, but maybe that can help you, waiting another answer. :)


  • Qt Champions 2016

    @Tapsa
    Hello,
    Select the widgets you want in the layout and click with the right mouse button and there's a "Lay out >" submenu, choose one of the layouts that suit you.

    Kind regards.



  • @Suji said:

    //Set the layout for your tab
    m_tab1->setLayout(vbox);

    I want to do this with the designer, but right-click menu of tab widgets has no layout options. Even tab_research has no layout options even though it has a layout. The designer is extremely counter intuitive. Obviously there is a need for a layout inside tab widgets, but nothing intuitive (like dragging layout on top of it or right-click menu) works.

    EDIT: I found the layout options in the top of the designer view.

    EDIT2: The layout options in the top are unrealiable. They may or may not change the layout of current tab or the whole main frame.


  • Qt Champions 2016

    @Tapsa
    As I noted you can use the context menus.

    1. Setting a layout to a widget:
      widget layout

    2. Setting a grid layout to a tab in a tab widget:
      tab widget page layout
      resulting in:
      tab widget page layout result

    It only takes some getting used to.
    Kind regards.



  • Hi @Tapsa,

    Glad to hear so ! That's why I don't like to build a project into Designer, like you said : it's not intuitive in my opinion, and people always warned me to not use it, because you don't control all you're doing.

    Wish you a good day !


  • Qt Champions 2016

    @Suji
    Hello,
    You could build the UI however you like, it's a personal choice and a preference. To this statement
    "That's why I don't like to build a project into Designer, like you said : it's not intuitive in my opinion, and people always warned me to not use it, because you don't control all you're doing.", however, I have to strongly object!
    Everything you code by hand is generated automatically from the uic that parses the form, with the added ability to actually see what you're doing in the designer. Although, one thing you should know to use the tool effectively is how layouts/widgets are nested. Once you grasp that the designer is incredibly powerful, allowing for rapid creation of almost anything.

    Kind regards.



  • @kshegunov

    Good point to note yes. I will think about it.


  • Qt Champions 2016

    I must also second @kshegunov
    that Designer is very powerful for designing and its not a all or nothing.

    You can easy mix Designer and in code gui generation for maximum flexibility.



  • I decided and started to create my GUI with C++ code only.
    Thanks for the tips, especially kshegunov. I tried to get that right-click menu from the list on right. I fail to grasp the logic why the right-click menu is different between clicking the design view and clicking the object list. It is very annoying and hard to create large scale windows with hundreds of controls using the designer.


  • Qt Champions 2016

    Well, navigating a project with
    hundreds of controls created from code will also be
    very verbose and hard.

    I like Designer a lot and have around 40 screen with many controls.
    Having that as code would be awful.

    Designer has flaws yes, but also many nice features.
    :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.