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



  • 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,



  • 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?



  • 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?



  • 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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.