tags:

views:

649

answers:

2

I am trying to get the QTabWidget automatically resized to fit the child tab when the child is added but have been unable to do so. I have created a form using Qt Designer and have inherited this using the 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 am adding the instance of the object to my QTabWidget using the addTab(). When I display the QTabWidget, I notice that it hasn't resized to fit the MyWidget instance. What do I need to do to ensure that the QTabWidget instance gets automatically resized?

A: 

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

Donotalo
+2  A: 

In designer, make sure you add a layout to your widget. Click on the widget's background so that way when you apply a layout, it applies to the whole widget. The trick is that the base (parent) widget that your form is built on needs a layout, and not just the items in the form.

Grid's are generally pretty easy to use. But sometimes the other ones are better. Designer can be tricky to use and takes a while to get used to. Basically every widget should probably have a layout applied to it. Strange things can happen when you don't.

jhufford