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]creating tabs
Forum Updated to NodeBB v4.3 + New Features

[Solved]creating tabs

Scheduled Pinned Locked Moved Mobile and Embedded
48 Posts 5 Posters 23.4k Views 1 Watching
  • 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
    #10

    :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
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #11

      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
      0
      • A Offline
        A Offline
        alfah
        wrote on last edited by
        #12

        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
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #13

          have a look at
          @indexOf()@

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cincirin
            wrote on last edited by
            #14

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

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

              u mean tabWidget->indexOf()???

              But i have not named each tab:(

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #16

                [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
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #17

                  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
                  0
                  • A Offline
                    A Offline
                    alfah
                    wrote on last edited by
                    #18

                    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
                    0
                    • A Offline
                      A Offline
                      alfah
                      wrote on last edited by
                      #19

                      eddy :)

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

                      alfah

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

                        [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
                        0
                        • C Offline
                          C Offline
                          cincirin
                          wrote on last edited by
                          #21

                          [quote author="alfah" date="1312359027"]what is widget(1)??[/quote]
                          @
                          QWidget* historyTab = tabWidget->widget(0);
                          QWidget* calenderTab = tabWidget->widget(1);
                          QWidget* statisticsTab = tabWidget(2);
                          @

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

                            ahh ok,
                            thanks cincirin

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

                              bq. 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?

                              try this

                              @ QGridLayout* grid = new QGridLayout();

                              for(int i=0;i<6;i++)     {
                                  for(int j=0;j<7;j++)         {
                                      cellBut[i][j]=new QPushButton(QString("%1 , %2").arg(i).arg(j));
                                      connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
                                      cellBut[i][j]->setFlat(true);
                                      grid ->addWidget(cellBut[i][j],i,j);
                                  }
                              }
                              
                              ui->tabWidget->widget(1)->setLayout(grid );@
                              

                              Qt Certified Specialist
                              www.edalsolutions.be

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

                                Thanks everybody :)

                                got it fixed :) this is wat Ive used jus in case somebody else needs it. My calender is put in vlayout. so my tabwidget has now the vLayout.

                                @

                                QVBoxLayout *vLayout=new QVBoxLayout;
                                tabWidget = new QTabWidget;
                                QWidget* pCalender = new QWidget;
                                QWidget* pHistory = new QWidget;
                                QWidget* pStatistics= new QWidget;
                                tabWidget->addTab(pCalender,tr("Calender"));
                                tabWidget->addTab(pHistory,tr("History"));
                                tabWidget->addTab(pStatistics,tr("Statistics"));
                                tabWidget->widget(0)->setLayout(vLayout);
                                

                                @

                                Last one, how to show another form when i click a tab. I have a function to show the history form. how do i call the functionwithout having to put a button on the History Tab??? :(

                                alfah

                                EDIT : i meant History Tab

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

                                  Great you made it.

                                  bq. Last one, how to show another form when i click a tab. I have a function to show the history form.

                                  Why do you want to do that? it's not clear for users they can access forms this way. Why don't you use a button for this?

                                  Qt Certified Specialist
                                  www.edalsolutions.be

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

                                    eddy
                                    There is an EDIT in my previous post :) I meant history tab not history form.

                                    I have made these tabs at the top to replace two buttons i have in the form.
                                    Its easier to switch between the tabs, so i have history button which when clicked goes to another form, the history form.

                                    Now im tryin to put the same thing into the tab. ie when I click the history tab, it should go to the history form
                                    This is my function which opens the history form
                                    @
                                    bool CalenderForm::showHistoryFrm()
                                    {

                                    HistoryForm *hHistoryFrm=new HistoryForm;
                                    hHistoryFrm->show();
                                    setCentralWidget(hHistoryFrm);
                                    hHistoryFrm->DisplayHistory();
                                    return true;
                                    delete hHistoryFrm;
                                    

                                    }
                                    @

                                    alfah

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

                                      can i do somethin like this/?
                                      @
                                      tabWidget->widget(1)->connect(tabWidget->widget(1),SIGNAL(clicked()),this,SLOT(showHistoryFrm()));
                                      @

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

                                        bq. Now im tryin to put the same thing into the tab. ie when I click the history tab, it should go to the history form
                                        This is my function which opens the history form

                                        What I meant is this is not good GUI design in my opinion. People using your program don't expect to click on a Tab to open a form. If I were you I would stick to the button solutions which you already have. There you can add icon/text saying "this buttons opens form..." or whatever you like. It will be more straightforward.
                                        BTW : the tabwidget doesn't have a clicked signal. I think it's intended that way for the reason I tried to explain.

                                        Qt Certified Specialist
                                        www.edalsolutions.be

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

                                          connect() function was automatically shown when i typed in tabWidget->widget(1) so there should be some function right?

                                          does tabwidget have any other signals tht can be used?

                                          well, i need to show the some history data when the history tab is pressed :( :( any other options than buttons?? It will look odd if there is jus a button in the history tab which when clicked will shoe the historyform :(

                                          alfah

                                          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