From bcfce0820cf51cd9ddc521846f45d43ac5bd8878 Mon Sep 17 00:00:00 2001 From: Calle Laakkonen Date: Tue, 11 Apr 2017 19:55:28 +0300 Subject: [PATCH] Add dropdown arrow to GroupedToolButton --- src/desktop/widgets/groupedtoolbutton.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/desktop/widgets/groupedtoolbutton.cpp b/src/desktop/widgets/groupedtoolbutton.cpp index 7ed4e9cd1..332fcdf85 100644 --- a/src/desktop/widgets/groupedtoolbutton.cpp +++ b/src/desktop/widgets/groupedtoolbutton.cpp @@ -99,8 +99,25 @@ void GroupedToolButton::paintEvent(QPaintEvent* event) painter.drawLine(x, y1, x, y2); } + const bool showDropdownArrow = menu() != nullptr && !text().isEmpty(); + + QRect textRect = opt.rect; + QRect arrowRect; + + if(showDropdownArrow) { + arrowRect = QRect(textRect.right() - 20, textRect.y(), 20, textRect.height()); + textRect.setWidth(textRect.width() - arrowRect.width()); + } + // Text + opt.rect = textRect; painter.drawControl(QStyle::CE_ToolButtonLabel, opt); + + // Dropdown arrow + if(showDropdownArrow) { + opt.rect = arrowRect; + painter.drawPrimitive(QStyle::PE_IndicatorArrowDown, opt); + } } #ifndef DESIGNER_PLUGIN