From ae72f5e47dd7cdf2d6546b958ec251f7e57899c9 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 7 Feb 2020 11:49:45 +0100 Subject: [PATCH] Changed sizeHints(), sizePolicy() and used updateGeometry() to properly size the tabBar --- src/DockAreaTabBar.cpp | 18 +++++++++++------- src/DockAreaTitleBar.cpp | 5 ++++- src/DockWidgetTab.cpp | 1 + src/stylesheets/default.css | 5 +++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 04f84af..8620f13 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -123,23 +123,24 @@ CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) : d(new DockAreaTabBarPrivate(this)) { d->DockArea = parent; - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setFrameStyle(QFrame::NoFrame); setWidgetResizable(true); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); d->TabsContainerWidget = new QWidget(); + d->TabsContainerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); d->TabsContainerWidget->setObjectName("tabsContainerWidget"); - setWidget(d->TabsContainerWidget); - d->TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight); d->TabsLayout->setContentsMargins(0, 0, 0, 0); d->TabsLayout->setSpacing(0); d->TabsLayout->addStretch(1); d->TabsContainerWidget->setLayout(d->TabsLayout); + setWidget(d->TabsContainerWidget); } + //============================================================================ CDockAreaTabBar::~CDockAreaTabBar() { @@ -350,6 +351,8 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab) { setCurrentIndex(d->CurrentIndex + 1); } + + updateGeometry(); } @@ -412,6 +415,8 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab) { d->updateTabs(); } + + updateGeometry(); } @@ -620,7 +625,8 @@ bool CDockAreaTabBar::isTabOpen(int Index) const QSize CDockAreaTabBar::minimumSizeHint() const { QSize Size = sizeHint(); - Size.setWidth(Super::minimumSizeHint().width());// this defines the minimum width of a dock area + //Size.setWidth(Super::minimumSizeHint().width());// this defines the minimum width of a dock area + Size.setWidth(10); return Size; } @@ -628,9 +634,7 @@ QSize CDockAreaTabBar::minimumSizeHint() const //=========================================================================== QSize CDockAreaTabBar::sizeHint() const { - QSize Size = Super::sizeHint(); - Size.setHeight(d->TabsContainerWidget->sizeHint().height()); - return Size; + return d->TabsContainerWidget->sizeHint(); } diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index d120b7a..93d2246 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -253,9 +253,12 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) : d->TopLayout->setContentsMargins(0, 0, 0, 0); d->TopLayout->setSpacing(0); setLayout(d->TopLayout); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); d->createTabBar(); + d->TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + d->TopLayout->addSpacerItem(horizontalSpacer); d->createButtons(); } diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 7da12c3..4e8323f 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -451,6 +451,7 @@ void CDockWidgetTab::setActiveTab(bool active) d->TitleLabel->style()->unpolish(d->TitleLabel); d->TitleLabel->style()->polish(d->TitleLabel); update(); + updateGeometry(); emit activeTabChanged(); } diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 5f7185d..9df5844 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -92,3 +92,8 @@ QScrollArea#dockWidgetScrollArea } +ads--CDockAreaTitleBar +{ + background: red; +} +