# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-09-13 11:23:26 # Node ID df43ee6b1f57c9075cd04ba8cedbd570fcf943b2 # Parent b6ab79693ccc202448d70c79ee30fc70ac7634e6 fixed double click not hiding tab widget issue on newer (>5.2) Qt versions diff --git a/hidabletabwidget.cpp b/hidabletabwidget.cpp --- a/hidabletabwidget.cpp +++ b/hidabletabwidget.cpp @@ -21,6 +21,9 @@ #include #include #include +#include + +#define DOUBLE_CLICK_DELAY (200) // ms HidableTabWidget::HidableTabWidget(QWidget *parent) : QTabWidget(parent), @@ -34,19 +37,22 @@ HidableTabWidget::HidableTabWidget(QWidg this->setCornerWidget(hideButton); connect(&hideAction, SIGNAL(toggled(bool)), this, SLOT(onHideAction(bool))); - connect(this, SIGNAL(tabBarClicked(int)), this, SLOT(onTabBarClicked())); - connect(this, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(onTabBarDoubleClicked())); + connectSignals(); } void HidableTabWidget::onHideAction(bool checked) { - if (checked) + if (checked) // hide { this->setMaximumHeight(this->tabBar()->height()); + disconnect(this, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(onTabBarDoubleClicked())); + QTimer::singleShot(DOUBLE_CLICK_DELAY, this, SLOT(connectSignals())); } - else + else // show { this->setMaximumHeight(100000); // just a very big number + disconnect(this, SIGNAL(tabBarClicked(int)), this, SLOT(onTabBarClicked())); + QTimer::singleShot(DOUBLE_CLICK_DELAY, this, SLOT(connectSignals())); } } @@ -59,3 +65,15 @@ void HidableTabWidget::onTabBarDoubleCli { hideAction.setChecked(true); } + +void HidableTabWidget::connectSignals() +{ + if (hideAction.isChecked()) // hidden + { + connect(this, SIGNAL(tabBarClicked(int)), this, SLOT(onTabBarClicked())); + } + else // shown + { + connect(this, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(onTabBarDoubleClicked())); + } +} diff --git a/hidabletabwidget.h b/hidabletabwidget.h --- a/hidabletabwidget.h +++ b/hidabletabwidget.h @@ -34,6 +34,8 @@ private slots: void onHideAction(bool checked); void onTabBarClicked(); void onTabBarDoubleClicked(); + + void connectSignals(); }; #endif // HIDABLETABWIDGET_H