From 24dd0a39d5dc55ac82f39878728d2cf679f75441 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 19 Jul 2018 11:11:57 +0200 Subject: [PATCH] Add a close button to the tabs. --- src/tabwidget.cpp | 11 ++++++++++- src/tabwidget.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 1b314ad..5b7fe4d 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -3,7 +3,8 @@ TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) { - + setTabsClosable(true); + connect(this, &QTabWidget::tabCloseRequested, this, &TabWidget::closeTab); } WebView* TabWidget::createNewTab(bool setCurrent) @@ -44,3 +45,11 @@ void TabWidget::setIconOf(WebView *webView, const QIcon &icon) { setTabIcon(indexOf(webView), icon); } + +void TabWidget::closeTab(int index) +{ + auto webview = widget(index); + removeTab(index); + webview->close(); + delete webview; +} diff --git a/src/tabwidget.h b/src/tabwidget.h index 08f48ef..bcb5264 100644 --- a/src/tabwidget.h +++ b/src/tabwidget.h @@ -14,6 +14,9 @@ public: void openUrl(const QUrl &url, bool newTab); void setTitleOf(WebView* webView, const QString& title); void setIconOf(WebView* webView, const QIcon& icon); + +public slots: + void closeTab(int index); }; #endif // TABWIDGET_H