Customize QDoubleSpinBox text align with CSS
-
wrote on 1 Sept 2021, 09:36 last edited by
-
Hello,
I try to customize a double spin box.
In Qt designer I have the following lines in the style sheet editor.
QDoubleSpinBox {font-size: 20px; text-align: right}
QPushButton{text-align: right}
text-align: right has no effect in the spin box
How can I change the alignment in the spin box?
wrote on 1 Sept 2021, 09:55 last edited by JonB 9 Jan 2021, 09:59@Bert59
AQSpinBox
has an internalQLineEdit
child for the number text. I won't lie to you, I have had trouble accessing that fully, and reported a bug, but it never got addressed. But I did successfully change the text alignment (mine was from code, not stylesheet, for this). That is what you will need to set thetext-align
on. Try it from stylesheet rule (QDoubleSpinBox.QLineEdit
or whatever the docs say the syntax is a for a child, I can't remember?), though that may be what I found did not work right. Or to verify my claim set the stylesheet directly from code onspinBox->lineEdit()
to check it works. Note that method isprotected
, to access you either need to sub-class or usespinBox->findChild<QLineEdit *>()
.
1/2