# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2015-07-30 14:39:34 # Node ID b30de3bb24210259c4a5c3180f647640ab963290 # Parent 250fc2df1c1bd97ffa8821a7d91fdc46b2133d16 added hide button to tab widget diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ add_executable(${PROGRAM_NAME} WIN32 customcheckablebutton.cpp plot.cpp zoomer.cpp + hidabletabwidget.cpp ${UI_FILES} misc/windows_icon.rc ) diff --git a/hidabletabwidget.cpp b/hidabletabwidget.cpp new file mode 100644 --- /dev/null +++ b/hidabletabwidget.cpp @@ -0,0 +1,37 @@ +#include "hidabletabwidget.h" +#include +#include + +HidableTabWidget::HidableTabWidget(QWidget *parent) : + QTabWidget(parent), + hideAction("▾", this) +{ + hideAction.setCheckable(true); + hideAction.setToolTip("Hide Panels"); + QToolButton* hideButton = new QToolButton(); + hideButton->setDefaultAction(&hideAction); + hideButton->setAutoRaise(true); + this->setCornerWidget(hideButton); + + connect(&hideAction, SIGNAL(toggled(bool)), this, SLOT(onHideAction(bool))); + connect(this, SIGNAL(tabBarClicked(int)), this, SLOT(onTabBarClicked())); +} + +void HidableTabWidget::onHideAction(bool checked) +{ + if (checked) + { + this->setMaximumHeight(this->tabBar()->height()); + this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + } + else + { + this->setMaximumHeight(100000); // just a very big number + this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + } +} + +void HidableTabWidget::onTabBarClicked() +{ + hideAction.setChecked(false); +} diff --git a/hidabletabwidget.h b/hidabletabwidget.h new file mode 100644 --- /dev/null +++ b/hidabletabwidget.h @@ -0,0 +1,19 @@ +#ifndef HIDABLETABWIDGET_H +#define HIDABLETABWIDGET_H + +#include +#include + +class HidableTabWidget : public QTabWidget +{ + Q_OBJECT +public: + explicit HidableTabWidget(QWidget *parent = 0); + QAction hideAction; + +private slots: + void onHideAction(bool checked); + void onTabBarClicked(); +}; + +#endif // HIDABLETABWIDGET_H diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -26,7 +26,7 @@ - + 0 @@ -603,6 +603,12 @@
plot.h
1 + + HidableTabWidget + QTabWidget +
hidabletabwidget.h
+ 1 +