Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Replace an ill-behaved GridLayout with custom Layout in a TabWidget



  • Qt 4.8.5, Windows XP and Windows 7, MS VS2008. I am using the designer to develop my rather complex dialog screen layout, which involves a QTabWidget. The layout in one of the tabs was very ill-beahved, so I wrote my own custom layout, which turned out to be quite simple, all it needed to do was arrange three widgets, two occupying the top 2/3 of the Widget and the third spreading itself across the bottom. When I used a Grid Layout, two of the widgets did not paint themselves entirely within the parent widget in many situations, particularly with lower screen resolutions. My custom layout simply calculates the coordinates based on dimensions of the parent widget (which needs to successfully paint itself with various screen resolutions). My question is how to replace the grid layout that designer creates with my custom one (patterned after the flow layout example). In the constructor of the dialog, I have the following small chunk of code:
    @
    mainTabLyt=new mainTabLayout(mainTab,2);
    int i,lyt_ct=mainTab->layout()->count();
    for (i=0;i<lyt_ct;i++)
    {
    mainTabLyt->addItem(mainTab->layout()->takeAt(0));
    }
    delete mainTab->layout();
    mainTab->setLayout(mainTabLyt);
    @
    As you can see, I first create my custom layout, 'mainTabLayout', then fill it with the Widgets that are in the GridLayout created by designer. Now to the question: in the setLayout documentation, it states that you first need to delete the existing layout before setting a new one, but there is no method to delete a layout. So I use the line
    @
    delete mainTab->layout();
    @

    Is that legitimate?? It seems to work, but makes me a bit nervaous that it is not the right way to do things.


Log in to reply