user24560
user24560

Reputation: 928

How do i cause a qtabwidget instance to automatically resize when child tabs are added to it?

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?

Upvotes: 0

Views: 3150

Answers (3)

Gibbs
Gibbs

Reputation: 11

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

Do not create the QTabWidget object in the main project.

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

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

The result is: it resizes as the mainwindow resizing.

Upvotes: 1

jhufford
jhufford

Reputation: 500

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.

Upvotes: 2

Donotalo
Donotalo

Reputation: 13025

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

Upvotes: 0

Related Questions