Matthiasabt
16th October 2013, 11:10
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
#ifndef TABWIDGET_H
#define TABWIDGET_H
#include <QTabWidget>
class TabWidget:public QTabWidget
{
Q_OBJECT
public:
TabWidget(QWidget *parent = 0);
public slots:
void closeTab(int index);
};
#endif // TABWIDGET_H
tabwidget.cpp
#include "tabwidget.h"
#include "settingstab.h"
#include <QDebug>
TabWidget::TabWidget(QWidget *parent):QTabWidget(parent) {
this->setParent(parent);
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
}
void TabWidget::closeTab(int index) {
this->removeTab(index);
}
code where i add the tab
void MainWindow::addMyTab() {
tabwidget->addTab(new SettingsTab(), "Settings");
}
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
#ifndef TABWIDGET_H
#define TABWIDGET_H
#include <QTabWidget>
class TabWidget:public QTabWidget
{
Q_OBJECT
public:
TabWidget(QWidget *parent = 0);
public slots:
void closeTab(int index);
};
#endif // TABWIDGET_H
tabwidget.cpp
#include "tabwidget.h"
#include "settingstab.h"
#include <QDebug>
TabWidget::TabWidget(QWidget *parent):QTabWidget(parent) {
this->setParent(parent);
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
}
void TabWidget::closeTab(int index) {
this->removeTab(index);
}
code where i add the tab
void MainWindow::addMyTab() {
tabwidget->addTab(new SettingsTab(), "Settings");
}