diff --git a/src/widgets/JupyterWidget.cpp b/src/widgets/JupyterWidget.cpp index 7565af32..c5850ac8 100644 --- a/src/widgets/JupyterWidget.cpp +++ b/src/widgets/JupyterWidget.cpp @@ -33,6 +33,7 @@ JupyterWebView *JupyterWidget::createNewTab() { auto webView = new JupyterWebView(this); ui->tabWidget->addTab(webView, "Tab"); + webView->setTabWidget(ui->tabWidget); return webView; } #endif @@ -73,6 +74,15 @@ void JupyterWidget::creationFailed() JupyterWebView::JupyterWebView(JupyterWidget *mainWidget, QWidget *parent) : QWebEngineView(parent) { this->mainWidget = mainWidget; + this->tabWidget = nullptr; + + connect(this, &QWebEngineView::titleChanged, this, &JupyterWebView::onTitleChanged); +} + +void JupyterWebView::setTabWidget(QTabWidget *tabWidget) +{ + this->tabWidget = tabWidget; + updateTitle(); } QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type) @@ -85,6 +95,27 @@ QWebEngineView *JupyterWebView::createWindow(QWebEnginePage::WebWindowType type) return nullptr; } } + +void JupyterWebView::onTitleChanged(const QString &) +{ + updateTitle(); +} + +void JupyterWebView::updateTitle() +{ + if (!tabWidget) + { + return; + } + + QString title = this->title(); + if (title.isEmpty()) + { + title = tr("Jupyter"); + } + tabWidget->setTabText(tabWidget->indexOf(this), title); +} + #endif #endif diff --git a/src/widgets/JupyterWidget.h b/src/widgets/JupyterWidget.h index 5b81627f..5bd49c1f 100644 --- a/src/widgets/JupyterWidget.h +++ b/src/widgets/JupyterWidget.h @@ -48,11 +48,19 @@ Q_OBJECT public: JupyterWebView(JupyterWidget *mainWidget, QWidget *parent = nullptr); + void setTabWidget(QTabWidget *tabWidget); + protected: QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override; +private slots: + void onTitleChanged(const QString &title); + private: JupyterWidget *mainWidget; + QTabWidget *tabWidget; + + void updateTitle(); }; #endif