summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtabbar.cpp
diff options
context:
space:
mode:
authorIvan Komissarov <ABBAPOH@gmail.com>2014-05-06 16:36:29 +0400
committerIvan Komissarov <ABBAPOH@gmail.com>2014-07-10 08:29:10 +0200
commit84c5e4866f8e825da306b8520f95b124e7c2c3ab (patch)
treed64bcf39a31de7e0b771c6a8b954591d2ab3c9e7 /src/widgets/widgets/qtabbar.cpp
parent5835407df13ecfd8d313eb2b8fc216f8cfe1f9e5 (diff)
Added autoHide property to QTabBar
This property is used to automatically hide tab bar if it has only one tab. Originally-by: Denis Kovalskiy <denimnumber1@gmail.com> Change-Id: I6967f760010fa55bad6a5986c29abe7ccf625cf8 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/widgets/qtabbar.cpp')
-rw-r--r--src/widgets/widgets/qtabbar.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index 789ec2f6fd..e8fdc65711 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -632,6 +632,14 @@ void QTabBarPrivate::layoutWidgets(int start)
}
}
+void QTabBarPrivate::autoHideTabs()
+{
+ Q_Q(QTabBar);
+
+ if (autoHide)
+ q->setVisible(q->count() > 1);
+}
+
void QTabBarPrivate::_q_closeTab()
{
Q_Q(QTabBar);
@@ -861,6 +869,7 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text)
}
tabInserted(index);
+ d->autoHideTabs();
return index;
}
@@ -936,6 +945,7 @@ void QTabBar::removeTab(int index)
setCurrentIndex(d->currentIndex - 1);
}
d->refresh();
+ d->autoHideTabs();
tabRemoved(index);
}
}
@@ -2267,6 +2277,36 @@ void QTabBar::setDocumentMode(bool enabled)
}
/*!
+ \property QTabBar::autoHide
+ \brief If true, the tab bar is automatically hidden when it contains less
+ than 2 tabs.
+ \since 5.4
+
+ By default, this property is false.
+
+ \sa QWidget::visible
+*/
+
+bool QTabBar::autoHide() const
+{
+ Q_D(const QTabBar);
+ return d->autoHide;
+}
+
+void QTabBar::setAutoHide(bool hide)
+{
+ Q_D(QTabBar);
+ if (d->autoHide == hide)
+ return;
+
+ d->autoHide = hide;
+ if (hide)
+ d->autoHideTabs();
+ else
+ setVisible(true);
+}
+
+/*!
Sets \a widget on the tab \a index. The widget is placed
on the left or right hand side depending upon the \a position.
\since 4.5