Add a close button to the tabs.

This commit is contained in:
Matthieu Gautier 2018-07-19 11:11:57 +02:00
parent ee2a55bcbf
commit 24dd0a39d5
2 changed files with 13 additions and 1 deletions

View File

@ -3,7 +3,8 @@
TabWidget::TabWidget(QWidget *parent) : TabWidget::TabWidget(QWidget *parent) :
QTabWidget(parent) QTabWidget(parent)
{ {
setTabsClosable(true);
connect(this, &QTabWidget::tabCloseRequested, this, &TabWidget::closeTab);
} }
WebView* TabWidget::createNewTab(bool setCurrent) WebView* TabWidget::createNewTab(bool setCurrent)
@ -44,3 +45,11 @@ void TabWidget::setIconOf(WebView *webView, const QIcon &icon)
{ {
setTabIcon(indexOf(webView), icon); setTabIcon(indexOf(webView), icon);
} }
void TabWidget::closeTab(int index)
{
auto webview = widget(index);
removeTab(index);
webview->close();
delete webview;
}

View File

@ -14,6 +14,9 @@ public:
void openUrl(const QUrl &url, bool newTab); void openUrl(const QUrl &url, bool newTab);
void setTitleOf(WebView* webView, const QString& title); void setTitleOf(WebView* webView, const QString& title);
void setIconOf(WebView* webView, const QIcon& icon); void setIconOf(WebView* webView, const QIcon& icon);
public slots:
void closeTab(int index);
}; };
#endif // TABWIDGET_H #endif // TABWIDGET_H