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 Update on Monday, May 27th 2025

[Solved]creating tabs

Scheduled Pinned Locked Moved Mobile and Embedded
48 Posts 5 Posters 22.9k 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
    #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
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #30

            bq. 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 :(

            why not put that form in that tab instead?

            yes there are other signals of course. The best way to find them is to use Qt Designer and use the "Edit signals slots" button or F4 to see them. for more info see the QT Designer manual.

            Qt Certified Specialist
            www.edalsolutions.be

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

              to put the form in the tab meaning??

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

                If you only have a button in the Tab and the only purpose for that button is to open another form, then you could eliminate that button and show the widgets immediately in your Tab.

                If you don't understand what I'm saying, maybe you could show us an image of your form and an image of the tab where the button is in?

                Qt Certified Specialist
                www.edalsolutions.be

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

                  I found a signal currentChanged for TabWidget, but i cant find out how to use it?

                  Any idea???

                  docs said

                  Qt Signal Documentation

                  @void currentChanged (int)
                  @
                  This is the default overload of this signal.

                  This signal is emitted whenever the current page index changes. The parameter is the new current page index position, or -1 if there isn't a new one (for example, if there are no widgets in the QTabWidget)

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

                    currentChanged will be invoked anytime you click on another tab than the current one. I don't think that is what you want or is it?

                    Qt Certified Specialist
                    www.edalsolutions.be

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

                      :(

                      yeaa u r right.

                      I tried using the following code, but then the same form is shown when both statics tab as well as the history tab is clicked even though i have connected two different forms
                      :(
                      @
                      tabWidget->widget(1)->connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(showHistoryFrm()));
                      tabWidget->widget(2)->connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(showOptionFrm()));
                      @

                      alfah

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

                        I think I don’t understand what you want exactly, maybe you could show us an image of your form ?

                        Qt Certified Specialist
                        www.edalsolutions.be

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

                          Rather than creating a new thread I thought its better this way,

                          @

                          tabWidget->setTabIcon(0,QIcon(":images\clock.png"));

                          @

                          The above code should set an icon in the first tab right?? But apparently its not!. I've put the image in the resource file.
                          ???

                          any idea

                          alfah

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

                            I think you missed a ""

                            Try this :
                            @tabWidget->setTabIcon(0,QIcon(":\images\clock.png")); @

                            Qt Certified Specialist
                            www.edalsolutions.be

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

                              '' did not do the trick :(

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

                                @tabWidget->setTabIcon(0,QIcon(":/images/clock.png")); @

                                works for me on the simulator.

                                the / or \ depends on your OS

                                Qt Certified Specialist
                                www.edalsolutions.be

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

                                  ahhh, , its not workin on the simulator or the device!!

                                  it is '/'. And i have corrected it. But still it does not work. Does image size gotta do anything with it??
                                  ive used 16x16. its almost 900 byte

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

                                    you can test if it's available from the resource editor using a dialog in Qt Designer and set the icon from there.

                                    Qt Certified Specialist
                                    www.edalsolutions.be

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

                                      Ive pulled in a tabWidget in the Designer. But i can only find iconsize property not the simple icon property with which you can set.

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

                                        no you have to use code to add it to a tab.

                                        But you could use a QLabel just for testing if the icon is reachable through the resource editor.

                                        Qt Certified Specialist
                                        www.edalsolutions.be

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

                                          it worked in the new project, both in the device as well as the simulator.
                                          @
                                          ui->tabWidget->setTabIcon(0,QIcon(":/images/clock.png"));
                                          @

                                          I think i know why it doesn work on my application.
                                          @
                                          tabWidget = new QTabWidget;
                                          tabWidget->setStyleSheet("QTabWidget::tab-bar{left:0px; width:350px; }\n"
                                          "QTabBar::tab{height:40px; width:95px; color:red; font:9pt; }\n");
                                          tabWidget->setTabIcon(0,QIcon(":/images/clock.png"));

                                          pCalender = new QWidget;
                                          pHistory = new QWidget;
                                          pStatistics= new QWidget;

                                          connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(onSelectTab(int)));
                                          tabWidget->addTab(pCalender,tr("Calender"));
                                          tabWidget->addTab(pHistory,tr("History"));
                                          tabWidget->addTab(pStatistics,tr("Statistics"));
                                          tabWidget->setTabIcon(0,QIcon(":/images/clock.png"));
                                          @

                                          EDIT : solved :D

                                          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