Skip to content

Don't reserve room for spinbox buttons if buttons disabled (Plasma 5.23)

(This is an older version of !120 (merged), rebased onto the Plasma/5.23 branch and updated for style. I'm resubmitting this since the 5.23 branch reverted !120 (merged). I tested this commit, but I think it's worth having more eyes to check I didn't screw up the behavior when refactoring the code. Do you plan to incorporate this fix into 5.23 or not?)

Previously, in Qt Widgets with the Breeze theme active, QAbstractSpinBox::setButtonSymbols(QAbstractSpinBox::NoButtons) would hide the buttons but leave a white space where the buttons would normally be. This changes the Breeze theme to skip adding the width of the hidden buttons to the spinbox's width.

This fixes QSpinBox and QDoubleSpinBox with buttons hidden. QDateTimeEdit is fixed as well, but it has empty whitespace to the right of the text both with and without buttons visible. (That's not related to this bug or fix though.)

The patch still compiles and works on the 5.23 branch:

Screenshot_20210924_135355_Instrument_01_-_Music_Box

Note that with or without this patch, I noticed that there's 2 pixels where the mouse cursor displays a text cursor, and clicking selects the numeric line editor, but the spinbox button is still highlighted:

Screenshot_20210924_142216

Technical details

labelRect.adjust(frameWidth... -frameWidth) is necessary to prevent the QLineEdit subcontrol from painting over the right border of the spinbox. But does this result in the QLineEdit being too small to fit the text (since we subtract 2*frameWidth from the width)? No, the spinbox's size (hint?) is obtained from the QLineEdit's size (hint?) by calling spinBoxSizeFromContents, which calls expandSize( size, frameWidth ), which adds 2*frameWidth to the height and width, So the final size hint of the QLineEdit is exactly equal to the contentsSize passed into spinBoxSizeFromContents. In fact, with regular spinboxes with buttons, the edit field subcontrol is slightly wider than necessary!

Also why is it called labelRect despite being an editable QLineEdit text field, and not a static label?

BUG: 440718

Edited by Nyan Pasu

Merge request reports