From: Soeren Apel Date: Mon, 10 Oct 2016 07:15:04 +0000 (+0200) Subject: MainWindow: Prevent the QTabWidget from collapsing when empty X-Git-Tag: pulseview-0.4.0~232 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc9646457d64b0a74e59ef511c3ae3db345bdbe4;p=pulseview.git MainWindow: Prevent the QTabWidget from collapsing when empty --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 39ce7ed6..36f9b1a0 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -248,6 +248,8 @@ shared_ptr MainWindow::add_session() void MainWindow::remove_session(shared_ptr session) { + int h = new_session_button_->height(); + for (shared_ptr view : session->views()) { // Find the dock the view is contained in and remove it for (auto entry : view_docks_) @@ -274,10 +276,21 @@ void MainWindow::remove_session(shared_ptr session) sessions_.remove_if([&](shared_ptr s) { return s == session; }); - // Update the window title if there is no view left to - // generate focus change events - if (sessions_.empty()) + if (sessions_.empty()) { + // When there are no more tabs, the height of the QTabWidget + // drops to zero. We must prevent this to keep the static + // widgets visible + for (QWidget *w : static_tab_widget_->findChildren()) + w->setMinimumHeight(h); + + int margin = static_tab_widget_->layout()->contentsMargins().bottom(); + static_tab_widget_->setMinimumHeight(h + 2 * margin); + session_selector_.setMinimumHeight(h + 2 * margin); + + // Update the window title if there is no view left to + // generate focus change events setWindowTitle(WindowTitle); + } } void MainWindow::setup_ui() @@ -318,11 +331,10 @@ void MainWindow::setup_ui() layout->setContentsMargins(2, 2, 2, 2); layout->addWidget(new_session_button_); - QWidget* static_tab_widget_ = new QWidget(); + static_tab_widget_ = new QWidget(); static_tab_widget_->setLayout(layout); session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner); - session_selector_.setTabsClosable(true); connect(new_session_button_, SIGNAL(clicked(bool)), diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 9d5b0412..0904845f 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -129,6 +129,7 @@ private: std::map< std::shared_ptr, QMainWindow*> session_windows_; + QWidget *static_tab_widget_; QToolButton *new_session_button_; QTabWidget session_selector_;