How do I get the qtabwidget instance to automatically resize when child tabs are added to them?

I am trying to get a QTabWidget automatically resized to fit the child tab when the child is added, but was unable to do so. I created a form using Qt Designer and inherited it using a single inheritance approach as follows.

class MyWidget : public QWidget
{
    Q_OBJECT

public:
    MyWidget(QWidget *parent = 0);
private:
    Ui::MyForm ui;
};

      

I have a QTabWidget and I add an object instance to my QTabWidget using addTab (). When I show the QTabWidget I notice that it hasn't changed according to the MyWidget instance. What do I need to do to ensure that the QTabWidget instance is automatically modified?

0


a source to share


3 answers


In the designer, make sure you add the layout to your widget. Click on the background of the widget, so when applying the layout, it will apply to the entire widget. The trick is that the base (parent) widget that your form is built on requires a layout, not just the elements on the form.



The grid is usually pretty easy to use. But sometimes others are better. A designer can be difficult to use and takes time to get used to. Basically, every widget should probably have a layout applied to it. Strange things can happen when you don't.

+2


a source


I believe this is a bug of the Creator (at least for V4.7.4 open source). My solution is as follows.

Don't create a QTabWidget object in the main project.

Create it independently (by creating Qt-> Form-class).



Then copy 3 files (.h, cpp, .ui) to the project and add them to the project.

Result: it resizes as the main window changes.

+1


a source


To fit any widget to its parent widget, you need to use a specific layout (grid, horizontal, vertical, etc.).

0


a source







All Articles