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. [SOLVED] Empty Tab added in QTabdWidget after adding dynamic tab in QTabWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Empty Tab added in QTabdWidget after adding dynamic tab in QTabWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k 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.
  • T Offline
    T Offline
    tesmai4
    wrote on last edited by
    #1

    I sub-class QTabWidget(myTabWdiget) and add this into mainwindow by promoting QTabWidget to myTabWidget. This works fine. There are no extra tabs added.

    I am adding tabs to myTabWidget dynamically in my program.

    [CODE] ui->myWidgetDays->addTab(new QWidget(),"Date");[/CODE]
    One [extra] empty tab is added into myTabWidget after adding all my [desired] dynamic tabs. This empty tab has index 0;

    I am only adding tabs in my program at one place. I have no idea why it is happening.

    Regards,

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Designer will probably add a signal tab to your QTabWidget derived class so your tabwidget already contains a tab. Maybe try to remove it in designer or when you start filling your tabs first check the number of tabs and remove all if any exist?

      Greetz, Jeroen

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tesmai4
        wrote on last edited by
        #3

        Thanks for your reply.

        There are no default tabs added in my application. Count of tabs before adding a tab, from my application, is zero.

        @
        qDebug()<<"Count of existing tabs: "<<ui->tabWidgetDays->count()<<", "<<ui->tabWidgetDays->currentIndex()<<endl;
        ui->tabWidgetDays->addTab(new QWidget(),dayTab );
        qDebug()<<"Count of existing tabs: "<<ui->tabWidgetDays->count()<<", Tab added for: "<<dayTab<<endl;
        @

        OUTPUT of the above lines is :
        Count of existing tabs: 0 , -1
        TabIndex : 0 [See Note]
        Count of existing tabs: 1 , Tab added for: ""
        Count of existing tabs: 1 , 0
        Count of existing tabs: 2 , Tab added for: "Tue Jul 9 2013"
        Count of existing tabs: 2 , 0
        Count of existing tabs: 3 , Tab added for: "Fri Jun 28 2013"
        Count of existing tabs: 3 , 0
        Count of existing tabs: 4 , Tab added for: "Wed Jun 26 2013"
        Count of existing tabs: 4 , 0
        Count of existing tabs: 5 , Tab added for: "Sat Jun 22 2013"

        @ connect (ui->tabWidgetDays, SIGNAL(currentChanged(int)),this, SLOT(tabIndexChanged(int)));@
        [NOTE] After printing first lines my signal/slot is executed and this line is printed. This line is not printed for remaining tab creation.

        Any idea why this is happening?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vaquita Tim
          wrote on last edited by
          #4

          bq. There are no default tabs added in my application

          That's odd, because my code agrees with what Jeroen said - I mean I had a dummy page which I had to delete :-

          @// Delete the dummy page inserted by the Designer code
          if( a_pParentTabControl->tabText( 0 ) == "<empty>" )
          {
          QWidget * pPage = a_pParentTabControl->widget( 0 );
          a_pParentTabControl->removeTab( 0 );
          delete pPage;
          }
          @

          ...though I changed it to be explicit by giving it a name.

          Nevertheless your test code appears to contradict us :-)

          re: [NOTE] this make sense - the tab index is only changed once, when the first page is added. After that, the tab index remains at 0 even though you add new pages.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tesmai4
            wrote on last edited by
            #5

            Thanks for your reply.
            There was a mistake in my logic, got the logic right, and now my tabs are added correctly.

            I'll check your code and update later.

            Thanks once again

            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