Results 1 to 10 of 10

Thread: Remove tabs from TabWidget

  1. #1
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Remove tabs from TabWidget

    Hi folks , I am using python, PyQt4 and I need to add and remove tabs from a QTabWidget after shown it. The widgets for tab pages are QVTKRenderWindowInteractor from VTK. What do I have to consider for doing this task, for example, flicker, objects deletion, etc.

    PS: sorry for my english, it's not so good.

  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: Remove tabs from TabWidget

    You call QTabWidget::addTab() and QTabWidget::removeTab() respectively.

  3. #3
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Re: Remove tabs from TabWidget

    yes, I know that, how to delete the widget (QVTKRenderWindowInteractor) from memory, when I try:

    interactor = tab_widget.widget(index)
    tab_widget.removeTab(index)
    interactor.close()

    I think PyQt4 or Qt must call the overloaded deleteLater method in the QVTKRenderWindowInteractor (python code) but it does not get called.

  4. #4
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Re: Remove tabs from TabWidget

    ohh, I forgot, __del__ method is jnot get called either

  5. #5
    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: Remove tabs from TabWidget

    You have to check in PyQt docs how to enforce deletion of Qt objects. Can't help you much with that. It's possible that you have to call setParent(None) on each object you want deleted.

  6. #6
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Re: Remove tabs from TabWidget

    setParent(None) doesn't work, the only thing that work is:

    interactor = tab_widget.widget(index)
    tab_widget.removeTab(index)
    interactor.close()
    interactor.deleteLater()

    #optionally
    del interactor

    but if Qt documentation say that when you create a widget with the attribute: WA_DeleteOnClose, when the widget is closed, it will be deleted and I did this when I create the widget:

    interactor = QVTKRenderWindowInteractor()
    interactor.setAttribute(QtCore.Qt.WA_DeleteOnClose )

  7. #7
    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: Remove tabs from TabWidget

    Quote Originally Posted by jmrbcu View Post
    setParent(None) doesn't work, the only thing that work is:
    Did you check in PyQt docs what works?

  8. #8
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Re: Remove tabs from TabWidget

    the qt documentation for tabwidget is almost the same so, I don't know where to look.

  9. #9
    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: Remove tabs from TabWidget

    I don't mean how to delete pages in tab widget but rather how to delete Qt objects in PyQt in general. I'm sure there is a dedicated call there somewhere to convince the Python garbage collector it should get rid of the object.

  10. #10
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4 Qt/Embedded

    Default Re: Remove tabs from TabWidget

    I think that doing:

    widget.close()
    widget.deleteLater()
    del widget

    # and optionally this if U really must
    import gc
    gc.collect()

    will do the trick

Similar Threads

  1. Add tab to tabwidget thru Designer.
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2010, 11:00
  2. TabWidget's Tab's parent
    By alisami in forum Qt Programming
    Replies: 12
    Last Post: 31st March 2009, 13:30
  3. Creating empty TabWidget (without any tabs)
    By momesana in forum Qt Tools
    Replies: 2
    Last Post: 2nd December 2007, 10:22
  4. TabWidget
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 17th May 2007, 21:07
  5. tabWidget Question
    By phlash in forum Qt Tools
    Replies: 1
    Last Post: 28th March 2007, 10:54

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.