Results 1 to 7 of 7

Thread: Removing Tabs

  1. #1
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    4
    Qt products
    Qt4

    Default Removing Tabs

    I'm having some problems with removing tabs from QTabWidget. I have this QTabWidget with a main tab, named (surprise!) mainTab. At runtime the user can open several new tabs to view text documents. In order to close these tabs again I have provided a push button, cmdClear. The code for the button is:

    Qt Code:
    1. void QtTextSearcher::on_cmdClear_clicked()
    2. {
    3. int count = ui.mainTab->count();
    4. int i = 1;
    5. for (i=1; i<count; ++i)
    6. {
    7. ui.mainTab->widget(i)->deleteLater();
    8. ui.mainTab->removeTab(i);
    9. }
    10. ui.txtOutput->clear();
    11. ui.txtLog->append("Cleared");
    12. }
    To copy to clipboard, switch view to plain text mode 

    When I press the buttton it doesn't delete all the document tabs however, it seems to always forget some. How come? I want it to delete all the tabs save the first mainTab.

    Also: How can I position my QTabWidget like in the Assistant? In the Assistant the Tabwidgets are touching the toolbar, in designer I can't seem to get my Tabwidget anywhere near the edges of the mainwindow.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Removing Tabs

    Tab indexes start from 0 and not from 1, so your for is invalid.

  3. #3
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    4
    Qt products
    Qt4

    Default Re: Removing Tabs

    But tab index = 0 is the first tab right? I don't want to remove that, just the remaining tabs

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Removing Tabs

    Quote Originally Posted by NewGuy
    Also: How can I position my QTabWidget like in the Assistant? In the Assistant the Tabwidgets are touching the toolbar, in designer I can't seem to get my Tabwidget anywhere near the edges of the mainwindow.
    Tweak the margins and spacing properties of the layout - set them to 0.

    About your tab problem... your code seems fine altough I wouldn't use deleteLater() just simply delete. And do that after removing the widget from the tab widget. It's possible that deleting will suffice and you won't have to remove the widget from the tab widget. If that doesn't help, could you try to reproduce the problem using a minimal compilable example?

  5. #5
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Removing Tabs

    see the code of assistant, they use some ugly tricks use the code.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Removing Tabs

    Quote Originally Posted by NewGuy
    I'm having some problems with removing tabs from QTabWidget.
    ...
    When I press the buttton it doesn't delete all the document tabs however, it seems to always forget some. How come? I want it to delete all the tabs save the first mainTab.
    Maybe you should remove the tabs from the end to the beginning. Each removeTab() reduces the count of the tabs, so the count isn't anymore the same than in the beginning of the loop.

    Qt Code:
    1. // "greater than zero" makes sure that the tab with index zero is left
    2. for (int i = count; i > 0; --i)
    3. {
    4. QWidget* tab = ui.mainTab->widget(i);
    5. ui.mainTab->removeTab(i);
    6. delete tab;
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    NewGuy (22nd July 2006)

  8. #7
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    4
    Qt products
    Qt4

    Default Re: Removing Tabs

    Great - that works just fine.

    About the position of my Tabwidget: When i force the widget into place by changing the geometry property it works just fine. When I resize the window it isn't resized with it however. If I try to make a layout with my mainwindow in order to fix this the tabwidget gets reset to a new position.
    Hope I have described the problem clear enough

Similar Threads

  1. Removing the selected row in a QTreeView
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 12:21
  2. Replies: 9
    Last Post: 9th May 2006, 20:53
  3. Tabs communication
    By therealjag in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2006, 19:19
  4. Replies: 13
    Last Post: 9th April 2006, 05:57

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.