haha great, so I don't have to worry about reporting it. Thanks
Thanks a lot for your question. I've tried to make my own mdi-style widget with QTabBar but have many problems with destruction. First of this two lines is exactly what I need.
It's quite simple if you inherit from a QTabWidget. Here's the test example i quickly designed.
{
Q_OBJECT
public :
UI_TabWidget
(QWidget *pParent
= 0);
void openTab();
private slots :
void closeTab(int iTabIndex);
};
class UI_TabWidget : public QTabWidget
{
Q_OBJECT
public :
UI_TabWidget(QWidget *pParent = 0);
void openTab();
private slots :
void closeTab(int iTabIndex);
};
To copy to clipboard, switch view to plain text mode
{
this->setMovable(true);
this->setTabsClosable(true);
QObject::connect(this,
SIGNAL(tabCloseRequested
(int)),
this,
SLOT(closeTab
(int)));
}
void UI_TabWidget::openTab()
{
//Here's a quick test widget
//Attaching it to a new tab
this->addTab(pTextEdit, "test");
}
void UI_TabWidget::closeTab(int iTabIndex)
{
this->widget(iTabIndex)->deleteLater();
this->removeTab(iTabIndex);
}
UI_TabWidget::UI_TabWidget(QWidget *pParent) : QTabWidget(pParent)
{
this->setMovable(true);
this->setTabsClosable(true);
QObject::connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
}
void UI_TabWidget::openTab()
{
//Here's a quick test widget
QTextEdit *pTextEdit = new TextEdit();
//Attaching it to a new tab
this->addTab(pTextEdit, "test");
}
void UI_TabWidget::closeTab(int iTabIndex)
{
this->widget(iTabIndex)->deleteLater();
this->removeTab(iTabIndex);
}
To copy to clipboard, switch view to plain text mode
Feel free to attach a custom made widget in openTab too, and you'll be able to access its member with
myCustomWidget *pWidget = dynamic_cast <myCustomWidget*>(this->widget(iTabIndex));
myCustomWidget *pWidget = dynamic_cast <myCustomWidget*>(this->widget(iTabIndex));
To copy to clipboard, switch view to plain text mode
Then you'll be able to make custom states to check before closing
if (!pWidget->m_bAllowedToClose)
//...
if (!pWidget->m_bAllowedToClose)
//...
To copy to clipboard, switch view to plain text mode
Have fun ;-)
Bookmarks