Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Label Text with two different alignments
Infestor last edited by
im currently struggling with a simple issue that i cant get solved. What i want to do is to list some items and their numerical value vertically in QLabels e.g.
However i would like to achieve that the text are aligned on the left and the numbers are aligned on the right. Is there a way to do this?
I tried using Layouts, but i have problems understanding how the different spacing methods all work.
I would go with a QFormLayout. It looks like what you are trying to get to.
JonB last edited by
You could use a
QGridLayoutwith two columns. You shouldn't need any "spacing methods" then.
JonB last edited by JonB
The trouble with
QFormLayoutis that it has inbuilt alignments according to overall style, being set for different windowing systems/styles. The OP specifies left alignment for the left-hand labels; but if you look at https://doc.qt.io/qt-5/qformlayout.html#details some styles align these right. That's why I suggested
Oh, I see there is
QFormLayout::setLabelAlignment()to alter that. Well, up to the OP. Note that
QFormLayoutis strictly intended for only two columns,
QGridLayoutyou can have however many you want.