Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTabWidget example
Qt 6.11 is out! See what's new in the release blog

QTabWidget example

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.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.
  • S Offline
    S Offline
    stretchthebits
    wrote on last edited by
    #1

    Hello all,
    Is there a QTabWidget example? One that programmaticly creates the control and places an edit box, a check box a button or something in some of the tabs?

    I am able to create the tab control but I don’t see my edit boxes.

    TABCTRLConversion=new QTabWidget(this);
    //Position the control
    TABCTRLConversion->setGeometry(5, 450, 500, 500);

    //We have to create a widget for each tab
    WIDGETTemperature=new QWidget(NULL);

    tempString="Temperature";
    TABCTRLConversion->addTab(WIDGETTemperature, tempString);
    WIDGETWeight1=new QWidget(NULL);
    tempString="Weight";
    TABCTRLConversion->addTab(WIDGETWeight1, tempString);
    WIDGETWeight2=new QWidget(NULL);
    tempString="Weight2";
    TABCTRLConversion->addTab(WIDGETWeight2, tempString);
    connect(TABCTRLConversion, SIGNAL(currentChanged(sint)), this, SLOT(OnSelchangeTabConversion(sint)));

    xSPosition1=30;
    yPosition1=500;
    yOffset1=50;
    yOffset2=22;
    EDITBOXCelsiusSize=71;
    STATICTemperature1=new QLabel(WIDGETTemperature);
    //Position the control
    STATICTemperature1->setGeometry(xSPosition1, yPosition1-yOffset2, 171, 22);
    STATICTemperature1->setText(tr("Convert °F to °C and K"));
    EDITFahrenheit=new QLineEdit(WIDGETTemperature);
    //Position the control
    EDITFahrenheit->setGeometry(xSPosition1, yPosition1, EDITBOXCelsiusSize, 22);
    EDITFahrenheit->setMaxLength(50);
    connect(EDITFahrenheit, SIGNAL(textChanged(QString)), this, SLOT(OnChangeEditFahrenheit(QString)));

    JonBJ 1 Reply Last reply
    0
    • S stretchthebits

      Hello all,
      Is there a QTabWidget example? One that programmaticly creates the control and places an edit box, a check box a button or something in some of the tabs?

      I am able to create the tab control but I don’t see my edit boxes.

      TABCTRLConversion=new QTabWidget(this);
      //Position the control
      TABCTRLConversion->setGeometry(5, 450, 500, 500);

      //We have to create a widget for each tab
      WIDGETTemperature=new QWidget(NULL);

      tempString="Temperature";
      TABCTRLConversion->addTab(WIDGETTemperature, tempString);
      WIDGETWeight1=new QWidget(NULL);
      tempString="Weight";
      TABCTRLConversion->addTab(WIDGETWeight1, tempString);
      WIDGETWeight2=new QWidget(NULL);
      tempString="Weight2";
      TABCTRLConversion->addTab(WIDGETWeight2, tempString);
      connect(TABCTRLConversion, SIGNAL(currentChanged(sint)), this, SLOT(OnSelchangeTabConversion(sint)));

      xSPosition1=30;
      yPosition1=500;
      yOffset1=50;
      yOffset2=22;
      EDITBOXCelsiusSize=71;
      STATICTemperature1=new QLabel(WIDGETTemperature);
      //Position the control
      STATICTemperature1->setGeometry(xSPosition1, yPosition1-yOffset2, 171, 22);
      STATICTemperature1->setText(tr("Convert °F to °C and K"));
      EDITFahrenheit=new QLineEdit(WIDGETTemperature);
      //Position the control
      EDITFahrenheit->setGeometry(xSPosition1, yPosition1, EDITBOXCelsiusSize, 22);
      EDITFahrenheit->setMaxLength(50);
      connect(EDITFahrenheit, SIGNAL(textChanged(QString)), this, SLOT(OnChangeEditFahrenheit(QString)));

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @stretchthebits
      I don't know whether your code does not work. One simply creates a QWidget for each "page", and put that into the QTabWidget via addTab(), as you seem to have done.

      Then, like any other QWidget, each of those page widgets should have a QLayout, and you add your sub-controls onto the page layouts as usual.

      S 1 Reply Last reply
      1
      • JonBJ JonB

        @stretchthebits
        I don't know whether your code does not work. One simply creates a QWidget for each "page", and put that into the QTabWidget via addTab(), as you seem to have done.

        Then, like any other QWidget, each of those page widgets should have a QLayout, and you add your sub-controls onto the page layouts as usual.

        S Offline
        S Offline
        stretchthebits
        wrote on last edited by
        #3

        @JonB What if I don't want to use QLayout and I want to position the edit boxes, check boxes, myself.
        In fact, when I change tabs, my OnSelchangeTabConversion(sint index) is not getting called.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @stretchthebits said in QTabWidget example:

          SIGNAL(currentChanged(sint))

          There is no such signal in QTabWidget - this is also printed during runtime on the console.
          And please use the new signal/slot syntax - then you can't hit such problems anymore.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          S 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @stretchthebits said in QTabWidget example:

            SIGNAL(currentChanged(sint))

            There is no such signal in QTabWidget - this is also printed during runtime on the console.
            And please use the new signal/slot syntax - then you can't hit such problems anymore.

            S Offline
            S Offline
            stretchthebits
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            Thanks, I changed that part to
            connect(TABCTRLConversion, &QTabWidget::currentChanged, this, &CChemicalADlg::OnSelchangeTabConversion);

            and it worked. One problem solved. One more to go.

            Christian EhrlicherC 1 Reply Last reply
            0
            • S stretchthebits

              @Christian-Ehrlicher
              Thanks, I changed that part to
              connect(TABCTRLConversion, &QTabWidget::currentChanged, this, &CChemicalADlg::OnSelchangeTabConversion);

              and it worked. One problem solved. One more to go.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @stretchthebits Then please mark the topic as solved, thx.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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