[Qt-interest] resize problem with nested layouts

Eckhard Jokisch e.jokisch at orange-moon.de
Thu Jul 30 16:51:20 CEST 2009


HI,
Iwant to place different widgets into the tabs of a tab view.
The widgets are created using designer as external *ui files.
In the external widget i.e. a QTableWidget is inserted in a gridlayout.
This widget allone resizes the QTableWidget according to the window size as 
exoected.
In the mainwindow I have a QTabWidget have a QGridLayout as child of a tab.
To the gridlayout of the tab I add the external widget (that contains a layout 
and a QTableView).
Now when changing the size of the mainwindow the tabWidget gets adjusted to 
the mainwindow size. But the tableWidget remeins constant.

How can I solve this?

Regards
Eckhard

mainwondow.cpp---
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "table.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // Table is a QWidget with a QTableWidget inside.
    // The QTableWidget is layed out within the QWidget in a gridlayout 
(resizing according to the widgetsize
    Table * table = new Table(this);
    ui->gridLayout_in_tab->addWidget(table,0,0,1,1);
}

from ui_mainwindow.h:
.................
class Ui_MainWindow
{
public:
    QWidget *centralWidget;
    QGridLayout *gridLayout;
    QTabWidget *tabWidget;
    QWidget *tab;
    QWidget *gridLayoutWidget;
    QGridLayout *gridLayout_in_tab;
    QWidget *tab_2;
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;

    void setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
        MainWindow->resize(600, 400);
        centralWidget = new QWidget(MainWindow);
        centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
        gridLayout = new QGridLayout(centralWidget);
        gridLayout->setSpacing(6);
        gridLayout->setMargin(11);
        gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
        tabWidget = new QTabWidget(centralWidget);
        tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
        tab = new QWidget();
        tab->setObjectName(QString::fromUtf8("tab"));
        gridLayoutWidget = new QWidget(tab);
        gridLayoutWidget-
>setObjectName(QString::fromUtf8("gridLayoutWidget"));
        gridLayoutWidget->setGeometry(QRect(0, 0, 361, 221));
        gridLayout_in_tab = new QGridLayout(gridLayoutWidget);
        gridLayout_in_tab->setSpacing(6);
        gridLayout_in_tab->setMargin(11);
        gridLayout_in_tab-
>setObjectName(QString::fromUtf8("gridLayout_in_tab"));
        gridLayout_in_tab->setContentsMargins(0, 0, 0, 0);
        tabWidget->addTab(tab, QString());
        tab_2 = new QWidget();
        tab_2->setObjectName(QString::fromUtf8("tab_2"));
        tabWidget->addTab(tab_2, QString());

        gridLayout->addWidget(tabWidget, 0, 0, 1, 1);

        MainWindow->setCentralWidget(centralWidget);
        menuBar = new QMenuBar(MainWindow);
        menuBar->setObjectName(QString::fromUtf8("menuBar"));
        menuBar->setGeometry(QRect(0, 0, 600, 23));
        MainWindow->setMenuBar(menuBar);
        mainToolBar = new QToolBar(MainWindow);
        mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
        MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
        statusBar = new QStatusBar(MainWindow);
        statusBar->setObjectName(QString::fromUtf8("statusBar"));
        MainWindow->setStatusBar(statusBar);

        retranslateUi(MainWindow);

        tabWidget->setCurrentIndex(0);


        QMetaObject::connectSlotsByName(MainWindow);
    } // setupUi
-----------------------------------------
from ui_table.h:class Ui_Table
{
public:
    QGridLayout *gridLayout;
    QTableWidget *tableWidget;

    void setupUi(QWidget *Table)
    {
        if (Table->objectName().isEmpty())
            Table->setObjectName(QString::fromUtf8("Table"));
        Table->resize(430, 311);
        gridLayout = new QGridLayout(Table);
        gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
        tableWidget = new QTableWidget(Table);
        tableWidget->setObjectName(QString::fromUtf8("tableWidget"));

        gridLayout->addWidget(tableWidget, 0, 0, 1, 1);


        retranslateUi(Table);

        QMetaObject::connectSlotsByName(Table);
    } // setupUi




More information about the Qt-interest-old mailing list