From fc30c11a4a7a7406fcce7bc48971efa56b0ae0a5 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Mon, 16 Aug 2021 18:18:30 -0400 Subject: [PATCH] kstyle: make spinbox buttons consistently widthed Now their width doesn't change when the height changes. BUG: 441036 FIXED-IN: 5.23 --- kstyle/breezestyle.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index f046802e..380bc2d0 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -2362,6 +2362,9 @@ namespace Breeze if( !spinBoxOption ) return ParentStyleClass::subControlRect( CC_SpinBox, option, subControl, widget ); const bool flat( !spinBoxOption->frame ); + const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); + const int buttonSize( option->fontMetrics.height() + 2*frameWidth ); + // copy rect auto rect( option->rect ); @@ -2372,30 +2375,31 @@ namespace Breeze case SC_SpinBoxUp: { auto r = rect; - r.setLeft(r.width()-r.height()); + r.setLeft(r.width()-buttonSize); return r; } case SC_SpinBoxDown: { auto r = rect; - r.setRight(r.height()); + r.setRight(buttonSize); return r; } case SC_SpinBoxEditField: { const bool showButtons = spinBoxOption->buttonSymbols != QAbstractSpinBox::NoButtons; + const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); + const int buttonSize( option->fontMetrics.height() + 2*frameWidth ); QRect r = rect; if( showButtons ) { auto w = r.width(); - r.setLeft(r.height()); - r.setRight(w-r.height()); + r.setLeft(buttonSize); + r.setRight(w-buttonSize); } // remove right side line editor margins - const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); if( !flat && r.height() >= option->fontMetrics.height() + 2*frameWidth ) { r.adjust( frameWidth, frameWidth, -frameWidth, -frameWidth ); } @@ -2695,7 +2699,8 @@ namespace Breeze // add in the buttons, which are square w/ length of height, and we have two of them const bool showButtons = spinBoxOption->buttonSymbols != QAbstractSpinBox::NoButtons; - if( showButtons ) size.rwidth() += size.height()*2; + const int buttonSize( option->fontMetrics.height() + 2*frameWidth ); + if( showButtons ) size.rwidth() += buttonSize*2; return size;