Results 1 to 3 of 3

Thread: QTabWidget inside QStackedWidget

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default QTabWidget inside QStackedWidget

    Hi,

    As the subject title implies, I have a QTabWidget inside a QStackedWidget.

    When I try to add a new tab by calling the following piece of code;

    Qt Code:
    1. _ui.tabWidget->addTab(temp, QString::number(p_Cid));
    To copy to clipboard, switch view to plain text mode 

    It adds the tab but overrides the most previously added tab. ( Also meaning that shows only the lastly added tab.)

    Any ideas?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTabWidget inside QStackedWidget

    _ui.tabWidget->addTab(temp, QString::number(p_Cid));
    This code implies that the tabWidget is *not* a child of the stack widget, so your UI is probably not defined correctly. If the tab widget was owned by the stack widget, then you would have at least one more level of indirection:

    Qt Code:
    1. _ui.stackWidget->tabWidget->addTab(temp, QString::number(p_Cid));
    To copy to clipboard, switch view to plain text mode 

    or, if the same thing was assembled via code:

    Qt Code:
    1. QStackedWidget * stack = new QStackedWidget( mainWidget );
    2. QTabWidget * tabWidget = new QTabWidget( stack );
    3. tabWidget->addTab( temp, QString::number( p_Cid ) );
    4. tabWidget->addTab( temp2, QString::number( p_Cid2 ); //etc.
    5. stack->addWidget( tabWidget );
    To copy to clipboard, switch view to plain text mode 

    And another question - what is "temp"? Is it a unique, new widget pointer that will end up being owned by the tab widget, or are you mistakenly trying to put the same widget instance into multiple tabs? If that's what you're doing, the tab widget probably sees the mistake and deletes the previous tab, since you can't add the same widget instance more than once.
    Last edited by d_stranz; 20th May 2012 at 18:55.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QTabWidget inside QStackedWidget

    Hi,

    ... or are you mistakenly trying to put the same widget instance into multiple tabs? If that's what you're doing, the tab widget probably sees the mistake and deletes the previous tab, since you can't add the same widget instance more than once.
    I don't think that should be a mistake. After all we may just want to play with one reference widget upon tab changes in the name of memory efficiency.

    Anyway, if that's the case, i let you know.

    Thanks.

Similar Threads

  1. QStackedWidget and QTabWidget Structure Advice
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2010, 10:20
  2. Replies: 3
    Last Post: 25th July 2010, 19:15
  3. Access objects inside QStackedWidget widgets.
    By Trader in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2010, 17:10
  4. Resizing QTableView inside a QTabWidget
    By Aslan in forum Newbie
    Replies: 2
    Last Post: 29th May 2010, 14:50
  5. Problem refreshing QTreeView inside QTabWidget
    By laugusti in forum Qt Programming
    Replies: 3
    Last Post: 16th December 2009, 09:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.