Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved]creating tabs

    Mobile and Embedded
    5
    48
    18271
    Loading More Posts
    • 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
      alfah last edited by

      hi

      Im new to creating widgets programmatically. I got the application running but no tabs were created

      This is my code
      @
      Tabs::Tabs(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::Tabs)
      {
      ui->setupUi(this);
      tabWidget = new QTabWidget;
      tabWidget->addTab(new QWidget,tr("History"));
      tabWidget->addTab(new QWidget,tr("Calender"));
      tabWidget->addTab(new QWidget,tr("Statistics")) ;
      mainLayout = new QVBoxLayout;
      mainLayout->addWidget(tabWidget);
      setLayout(mainLayout);

      }
      @
      and in the header file
      I've declared the following
      @
      QTabWidget *tabWidget;
      QVBoxLayout *mainLayout;
      @

      alfah

      1 Reply Last reply Reply Quote 0
      • C
        cincirin last edited by

        Include the header where HistoryTab and others are declared.

        1 Reply Last reply Reply Quote 0
        • A
          alfah last edited by

          cincirin,

          I got rid of the errors but have the program running, but i cant find any tabs created.
          Jus a blank screen !! :(

          alfah

          1 Reply Last reply Reply Quote 0
          • D
            DenisKormalev last edited by

            Use this instead of last line in your ctor
            @
            centralWidget->setLayout(mainLayout);
            @

            1 Reply Last reply Reply Quote 0
            • A
              alfah last edited by

              denis,

              i can jus use centralWidget?? wat is it??

              i get the follwing error " invalid use of member".

              alfah

              1 Reply Last reply Reply Quote 0
              • E
                Eddy last edited by

                I think you need to use
                @setCentralWidget @ first

                Qt Certified Specialist
                www.edalsolutions.be

                1 Reply Last reply Reply Quote 0
                • A
                  alfah last edited by

                  :( it does work tht way either.

                  1 Reply Last reply Reply Quote 0
                  • D
                    DenisKormalev last edited by

                    oops, I meant
                    @
                    centralWidget()->setLayout(mainLayout);
                    @

                    Eddy, looks like it is form created from designer, so central widget should be there.

                    1 Reply Last reply Reply Quote 0
                    • C
                      cincirin last edited by

                      Tabs is the class derived from QMainWindow ? Can you show us the header and part of the code where you instantiate the Tabs class ?

                      1 Reply Last reply Reply Quote 0
                      • A
                        alfah last edited by

                        :D :D yeaa denis i got it right, Thank you!

                        so if i want to create buttons in the history tab? how to i go abt it???. I meant how do i acces each tab separately??

                        alfah

                        1 Reply Last reply Reply Quote 0
                        • E
                          Eddy last edited by

                          Did you use it like this ? :

                          this is the way moc does it when looking in the ui_tabs.h file
                          @centralwidget = new QWidget(Tabs); // it is just a temporary name
                          ...
                          Tabs->setCentralWidget(centralwidget);@

                          @Denis
                          Yes, you are right!

                          EDIT : too late ;)

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply Reply Quote 0
                          • A
                            alfah last edited by

                            eddy,

                            @
                            Tabs::Tabs(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::Tabs)
                            {
                            ui->setupUi(this);
                            tabWidget = new QTabWidget;
                            tabWidget->addTab(new QWidget,tr("History"));
                            tabWidget->addTab(new QWidget,tr("Calender"));
                            tabWidget->addTab(new QWidget,tr("Statistics"));
                            mainLayout = new QVBoxLayout;
                            mainLayout->addWidget(tabWidget);
                            centralWidget()->setLayout(mainLayout);

                            }
                            @

                            i still do not know how to make individual buttons on each tab :(

                            alfa

                            1 Reply Last reply Reply Quote 0
                            • E
                              Eddy last edited by

                              have a look at
                              @indexOf()@

                              Qt Certified Specialist
                              www.edalsolutions.be

                              1 Reply Last reply Reply Quote 0
                              • C
                                cincirin last edited by

                                @QTabWidget::widget(int index)@ return the tab page.
                                Then you can create buttons with returned parent.

                                1 Reply Last reply Reply Quote 0
                                • A
                                  alfah last edited by

                                  u mean tabWidget->indexOf()???

                                  But i have not named each tab:(

                                  1 Reply Last reply Reply Quote 0
                                  • G
                                    giesbert last edited by

                                    [quote author="alfah" date="1312355523"]eddy,

                                    @
                                    Tabs::Tabs(QWidget *parent) :
                                    QMainWindow(parent),
                                    ui(new Ui::Tabs)
                                    {
                                    ui->setupUi(this);
                                    tabWidget = new QTabWidget;
                                    tabWidget->addTab(new QWidget,tr("History"));
                                    tabWidget->addTab(new QWidget,tr("Calender"));
                                    tabWidget->addTab(new QWidget,tr("Statistics"));
                                    mainLayout = new QVBoxLayout;
                                    mainLayout->addWidget(tabWidget);
                                    centralWidget()->setLayout(mainLayout);

                                    }
                                    @

                                    i still do not know how to make individual buttons on each tab :(

                                    alfa
                                    [/quote]

                                    You can event add custom widgets to the tab widget, so go this way:

                                    @
                                    Tabs::Tabs(QWidget *parent) :
                                    QMainWindow(parent),
                                    ui(new Ui::Tabs)
                                    {
                                    ui->setupUi(this);
                                    tabWidget = new QTabWidget;

                                    QWidget* pHistory = new QWidget;
                                    // fill pHistory here
                                    QPushButton* p = new QPushButton(tr("my text"), pHistory);
                                    
                                    
                                    tabWidget->addTab(pHistory,tr("History"));
                                    tabWidget->addTab(new QWidget,tr("Calender"));
                                    tabWidget->addTab(new QWidget,tr("Statistics"));
                                    mainLayout = new QVBoxLayout;
                                    mainLayout->addWidget(tabWidget);
                                    centralWidget()->setLayout(mainLayout);
                                    

                                    }
                                    @

                                    Nokia Certified Qt Specialist.
                                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                    1 Reply Last reply Reply Quote 0
                                    • E
                                      Eddy last edited by

                                      in that case use cinrin's solution :

                                      for example :

                                      @ QPushButton* ppp = new QPushButton("testing" );
                                      QHBoxLayout* hhh = new QHBoxLayout();
                                      hhh->addWidget(ppp);
                                      ui->tabWidget->widget(1)->setLayout(hhh);@

                                      I set up an example layout for you to control size and position.

                                      EDIT : this time Gerolf was faster ;)

                                      Qt Certified Specialist
                                      www.edalsolutions.be

                                      1 Reply Last reply Reply Quote 0
                                      • A
                                        alfah last edited by

                                        gerolf,

                                        yea i could make buttons. Now im working on somethin a bit more complex than a single button.
                                        I have made a calender using an array of buttons, its the same thing like the default calender.

                                        Would it be possible to put in the whole calender in to one of the tab, jus as you have created a single button.???
                                        It requires mainly 4 funtions to create the whole calender
                                        @
                                        initMemberVariable();

                                        initMonthYear();
                                        
                                        initWeekDay();
                                        
                                        createLayout();
                                        

                                        @

                                        @
                                        bool CalenderForm::initMemberVariable()
                                        {

                                        selectedDate=QDate::currentDate();
                                        
                                        controlsLayout = new QGridLayout();
                                        
                                        monthValue=selectedDate.month();
                                        
                                        pLabelStatus=new QLabel;
                                        
                                        pLabelStatus->setStyleSheet("color:black");
                                        
                                        
                                        for(int i=0;i<6;i++)
                                        {
                                            for(int j=0;j<7;j++)
                                            {
                                        
                                               cellBut[i][j]=new QPushButton(this);
                                               connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
                                               cellBut[i][j]->setFlat(true);
                                        
                                            }
                                        }
                                        return true;
                                        

                                        }
                                        @

                                        This is where the buttons are created. I want them to be created in the calender tab.

                                        Could you guide me on how to go abt it?

                                        alfa

                                        1 Reply Last reply Reply Quote 0
                                        • A
                                          alfah last edited by

                                          eddy :)

                                          yeaa a wee bit faster. could you check on the above posts and give your opinion?

                                          alfah

                                          1 Reply Last reply Reply Quote 0
                                          • A
                                            alfah last edited by

                                            [quote author="Eddy" date="1312356252"]in that case use cinrin's solution :

                                            for example :

                                            @ QPushButton* ppp = new QPushButton("testing" );
                                            QHBoxLayout* hhh = new QHBoxLayout();
                                            hhh->addWidget(ppp);
                                            ui->tabWidget->widget(1)->setLayout(hhh);@

                                            I set up an example layout for you to control size and position.

                                            EDIT : this time Gerolf was faster ;)[/quote]

                                            what is widget(1)??

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post