From 1961ea465f9fd1d5546f5d0100b8663f37e92150 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 28 Nov 2016 12:49:43 +0100 Subject: [PATCH] Handle tab button being on either side on QTabBar without crashing --- .../toolwindowmanager/ToolWindowManagerArea.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp index 251d78b2c..9ff1d7c47 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp @@ -28,6 +28,15 @@ #include #include +static void showCloseButton(QTabBar *bar, int index, bool show) { + QWidget *button = bar->tabButton(index, QTabBar::RightSide); + if(button == NULL) + button = bar->tabButton(index, QTabBar::LeftSide); + + if(button) + button->resize(show ? QSize(16, 16) : QSize(0, 0)); +} + ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget *parent) : QTabWidget(parent) , m_manager(manager) @@ -58,7 +67,7 @@ void ToolWindowManagerArea::addToolWindows(const QList &toolWindows) foreach(QWidget* toolWindow, toolWindows) { index = addTab(toolWindow, toolWindow->windowIcon(), toolWindow->windowTitle()); if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) { - tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0); + showCloseButton(tabBar(), index, false); } } setCurrentIndex(index); @@ -77,9 +86,9 @@ void ToolWindowManagerArea::updateToolWindow(QWidget* toolWindow) { int index = indexOf(toolWindow); if(index >= 0) { if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) { - tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0); + showCloseButton(tabBar(), index, false); } else { - tabBar()->tabButton(index, QTabBar::RightSide)->resize(16, 16); + showCloseButton(tabBar(), index, true); } tabBar()->setTabText(index, toolWindow->windowTitle()); }