Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] Error with layouts
QtWS25 Last Chance

[Solved] Error with layouts

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 3 Posters 6.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alfah
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alfah
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Are you using Qt Designer or code?

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alfah
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                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.

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alfah
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alfah
                    wrote on last edited by
                    #9

                    so solved :)

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved