[Solved] Error with layouts



  • hello everybody.

    Cant we place a layout on to another Layout??? I get the following warning when I run the application

    "attempting to set QLayout on Qwidget which has already a layout". I dont get the output either, is it because of this warning?

    alfah


  • Moderators

    This warning tells you the widget you want to set a layout on has already one and you cannot add another one on the same level.

    You can use a layout IN another layout though.



  • This warning appears while attempting this.
    A vlayout is being set to a QWidget and this QWidget is set to a tabWidget.

    can this warning not give the desired output?
    Could you explain on how one layout can be used inside another?

    alfah


  • Moderators

    Are you using Qt Designer or code?



  • everythig is code written. Im jus trying to achieve my tabs not refreshing through some alternative.
    Instead of creating the obj of the class and putting them in tab, i tried creating a layout and then assign them to a tab.



  • Just use addLayout (as you would use addWidget) to add another layout to a layout.

    Can you provide some code so we can take a look at it?


  • Moderators

    example with 3 buttons in layout in QTabwidget:
    @ horizontalLayout = new QHBoxLayout(Dialog);
    tabWidget = new QTabWidget(Dialog);
    tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
    tab = new QWidget();
    tabWidget->addTab(tab, QString());
    tab_2 = new QWidget();
    horizontalLayout_2 = new QHBoxLayout(tab_2);
    verticalLayout = new QVBoxLayout();
    pushButton = new QPushButton(tab_2);

        verticalLayout->addWidget(pushButton);
    
        pushButton_2 = new QPushButton(tab_2);
    
        verticalLayout->addWidget(pushButton_2);
    
        pushButton_3 = new QPushButton(tab_2);
    
        verticalLayout->addWidget(pushButton_3);
    
        horizontalLayout_2->addLayout(verticalLayout);
    
        tabWidget->addTab(tab_2, QString());
        tab_3 = new QWidget();
        tabWidget->addTab(tab_3, QString());
    
        horizontalLayout->addWidget(tabWidget);@
    

    EDIT : this is code generated by Qt Designer in a ui_yourForm.h and helps a lot to learn how to use QLayouts and QWidgets in it.



  • hey
    I have solved it using another alternative. Instead of creating class instances and showing every time. I manually created the whole form with all the labels and text boxes. Put all of them in a layout. And placed the layout in the tabs.

    @
    void MainWindow::displayTabs()
    {
    tabWidget = new QTabWidget;
    pCalender = new QWidget;
    pHistory = new QWidget;
    pStatistics= new QWidget;

    pCalender->setStyleSheet("background-color: rgb(224, 220, 201);");
    pHistory->setStyleSheet("background-color: rgb(224, 220, 201);");
    pStatistics->setStyleSheet("background-color: rgb(224, 220, 201);");
    
    
    connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(a(int)));
    tabWidget->addTab(pCalender,tr("Calender"));
    tabWidget->addTab(pHistory,tr("History"));
    tabWidget->addTab(pStatistics,tr("Statistics"));
    
    
    setCentralWidget(tabWidget);
    

    }

    void MainWindow::a(int index)
    {
    switch(index)
    {
    case 0:
    calCal();
    break;

        case 1:
        calHist();
        break;
    
        case 2:
        calStat();
        break;
    
    }
    

    }

    void MainWindow::calCal()
    {
    CalenderForm *c=new CalenderForm();
    qDeleteAll(pCalender->children());
    pCalender->setLayout(c->vLayout);
    pCalender->show();
    }

    void MainWindow::calHist()
    {
    qDebug()<<"hello World";
    test *t=new test();
    qDeleteAll(pHistory->children());
    pHistory->setLayout(t->vLayout);
    t->DisplayHistory();
    pHistory->show();

    }
    @

    :) :)
    alfah



  • so solved :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.