Results 1 to 7 of 7

Thread: Removing a tab in QTabWidget removes tabs to right as well

  1. #1
    Join Date
    Sep 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Removing a tab in QTabWidget removes tabs to right as well

    Hi

    I am using a QTabWidget and have implemented a method which reacts to the "oncloseRequest" signal (clicking on the close icon of a tab):
    Qt Code:
    1. void generat0rX::sceneTabRemove_slot(int index)
    2. {
    3. sceneTabWidget->currentWidget()->deleteLater();
    4. sceneTabWidget->removeTab(index);
    5. }
    To copy to clipboard, switch view to plain text mode 

    My problem is that not only the active tab is deleted, but all to the right of it as well (having higher indexes than the currently active one).

    Is there a fundamental mistake I am making in the method above?

    Thanks & regards,
    Michael

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi,

    You could put a qDebug() << "tab index " << index << "removed" in this slot.

    I guess it gets called recursively until there are no more tabs. You should see this in the debug output then.

    Best regards,
    Marc

  3. The following user says thank you to marcvanriet for this useful post:

    mboeni (19th October 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi Marc

    I did as you proposed and can clarify the behaviour a bit (I found the pattern):
    Whenever i close a tab, the one immediately to its left (current index - 1) is also deleted. This behaviour is constant and reproducible.

    I also think I understood the problem: Both commands (removeTab, deleteLater) actually remove the tab! So first the tab is removed, then the one further down the index becomes current and is also removed (by the second command).

    As I want to delete the widget (memory considerations) when it is closed, would "deleteLater()" be better? or is the object deleted automatically by using removeTab?

    Cheers,
    Michael

  5. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi,

    I'm sorry but I'm not sure. According to the documentation of removeTab, the widget itself is not deleted, so you have to take care of that yourself. If you do deleteLater() only, does it remove itself from the tabWidget ? The documentation doesn't say that the tabWidget becomes parent of your widget, so I wouldn't know how your widget can know that it is part of a tabwidget.

    Maybe you could try :
    Qt Code:
    1. QWidget *pWidget = sceneTabWidget->widget(index);
    2. if( pWidget!=NULL)
    3. {
    4. sceneTabWidget->removeTab(index);
    5. pWidget->deleteLater();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Best regards,
    Marc

  6. #5
    Join Date
    Sep 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi Marc

    I currently use the following code:
    Qt Code:
    1. void generat0rX::sceneTabRemove_slot(int index)
    2. {
    3. sceneTabWidget->currentWidget()->deleteLater();
    4. }
    To copy to clipboard, switch view to plain text mode 

    And it indeed does remove the tab from the QTabWidget! Perhaps this is a glitch in the documentation.

    As long as it works stable (or until someone ponts out that this is ultimately wrong) I think I'll leave it like this.

    Does the above work for you too?

    Cheers,
    michael

  7. #6
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi,

    I have no app where I do this, so I can't tell.
    You could put a qDebug() << "widget deleted" in the destructor of your widget to see if the destructor gets called. If it does, I guess it is OK.

    Best regards,
    Marc

  8. #7
    Join Date
    Sep 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Removing a tab in QTabWidget removes tabs to right as well

    Hi Marc

    Yep, the widget gets deleted properly. looks right to me, then

    Cheers,
    Michael

Similar Threads

  1. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 12:20
  2. Qtabwidget - how to add a button to all tabs?
    By creep33 in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2010, 19:05
  3. QTabWidget - Add Tabs dynamically
    By fruzzo in forum Qt Programming
    Replies: 11
    Last Post: 27th February 2008, 08:26
  4. Switching off all tabs in QTabWidget
    By Gopala Krishna in forum Qt Programming
    Replies: 7
    Last Post: 30th August 2006, 17:10
  5. Removing Tabs
    By NewGuy in forum Qt Programming
    Replies: 6
    Last Post: 22nd July 2006, 22:46

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.