WText::setTextSize ?

Added by Christophe Delépine over 1 year ago

Hi,

Is there an equivalent of WLineEdit::setTextSize for WText ?

Basically, i want a minimum number of characters to be printed. If the string to be printed is shorter than this number, the result is padded with blank spaces.

The use case is to vertically right-align a set of strings. I could put the strings in a WGridLayout with RightAlign in the cells but surely there must be a simpler solution

Thanks


Replies

RE: WText::setTextSize ? - Added by Christophe Delépine over 1 year ago

Hi

One solution i have found is to put each WText in a WContainerWidget with a WHBoxLayout and call WContainerWidget::resize() with a fixed width and auto height (width is chosen according to the longest string)
The advantage is that all my WText are independent and don't have to be placed in a WVBoxLayout or WGridLayout.

In any case, a dedicated WText::setTextSize() would be the most convenient solution...

RE: WText::setTextSize ? - Added by Koen Deforche over 1 year ago

Hey,

To vertically right-align a set of strings, you can simply add each string as a WText to a WContainerWidget, setInline(false) for each text, and setContentAlignment(AlignRight) on the container widget.

I hope that helps ?

Regards,
koen

RE: WText::setTextSize ? - Added by Christophe Delépine over 1 year ago

Hi,

No i can't do that because i need to layout each WText with some other widgets. So all WText cannot be in the same container.
A picture is worth a thousand words so here is a partial snapshot of my gui.

"Emission Rate", "Emitter Life Time" and "Emission Angle" must be vertically right-aligned. Also, each string must be horizontally middle-aligned with the line edit and slider on its right. If a string is preceded with a +/- push button, then sub-widgets must be displayed in the same manner but slightly shifted on the right (in the example a "Var Random" parameter has appeared). The push-button must remain horizontally middle-aligned with the string.

I have highlighted in red the forced pixel size of the WText on the snapshot

Being able to fix the size of strings is convenient in this case because they don't have to be in the same container or layout which simplifies the building of the widget tree.

Regards
Christophe

gui.jpg (10.1 KB)

RE: WText::setTextSize ? - Added by Koen Deforche over 1 year ago

Hey,

Unfortunately this where CSS is entirely disappointing. You cannot reliably set the size of a WText since it is an inline widget. A workaround is to give it 'position: inline-block' but that is not supported by IE. Alternatively you need to make it block level and float it to the left but then you lose the automatic vertical alignment you look for.

For a frustrating account of the problems and solutions: http://flipc.blogspot.com/2009/02/damn-ie7-and-inline-block.html

I am not sure what setTextSize() would do differently than setting the width using resize() ?

Regards,
koen