Results 1 to 2 of 2

Thread: QTabWidget not deleting the widget of a tab when this tab is closed

  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QTabWidget not deleting the widget of a tab when this tab is closed

    Hello,

    I have a program whick has a TabWidget as the CentralWidget and i want the tabs to be closeable, but when I close a specific tab, the widget it contains is not deleted.
    The TabWidget that I use is derived from the QTabWidget.
    Maybe I must set the parent of the widget to be the tab, but how should i do that?

    tabwidget.h
    Qt Code:
    1. #ifndef TABWIDGET_H
    2. #define TABWIDGET_H
    3.  
    4. #include <QTabWidget>
    5.  
    6. class TabWidget:public QTabWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. TabWidget(QWidget *parent = 0);
    11.  
    12. public slots:
    13. void closeTab(int index);
    14. };
    15.  
    16. #endif // TABWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    tabwidget.cpp
    Qt Code:
    1. #include "tabwidget.h"
    2. #include "settingstab.h"
    3. #include <QDebug>
    4.  
    5. TabWidget::TabWidget(QWidget *parent):QTabWidget(parent) {
    6. this->setParent(parent);
    7. connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    8. }
    9.  
    10. void TabWidget::closeTab(int index) {
    11. this->removeTab(index);
    12. }
    To copy to clipboard, switch view to plain text mode 

    code where i add the tab
    Qt Code:
    1. void MainWindow::addMyTab() {
    2. tabwidget->addTab(new SettingsTab(), "Settings");
    3. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget not deleting the widget of a tab when this tab is closed

    removeTab(index) - removes the tab at position index from this stack of widgets. The page widget itself is not deleted.
    You can remove your widget using function QWidget * QTabWidget::widget(int index) const

Similar Threads

  1. Replies: 6
    Last Post: 21st August 2013, 12:53
  2. How to block a software or widget from being closed
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 27th April 2013, 15:25
  3. Deleting a child widget
    By zgulser in forum Qt Programming
    Replies: 12
    Last Post: 14th December 2012, 18:36
  4. deleting a widget
    By john_god in forum General Programming
    Replies: 1
    Last Post: 30th December 2010, 09:36
  5. Closing program when widget is closed.
    By metdos in forum Newbie
    Replies: 27
    Last Post: 30th July 2009, 13:14

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.