Centered and right-justified

Is there a way to right-justify centered values? Basically, I want values in a table to be in the center of the cell so that the longest value is centered and all other values are right-justified in relation to the longest value.

Here is a picture depicting what I’m trying to accomplish:
(As this is my first post, I’m not sure if the picture will show up correctly.)

The first column (Value) consists of integer values centered in the column.
The second column (Value 2) is a string representation of those same values, with spaces added to the beginning of the shorter values in an attempt to right-justify them to the longest one (“2048”).
Unfortunately, it’s not as easy as adding one space per “missing” character since this used a proportional font.

I think that using a monospace font and manual padding the values is going to be the only way to achieve this.

Set the columns to right justification. Use a property change event on “data” to determine the longest value, then update the column attributes dataset to have a suffix of the required number of spaces.

pturmel’s work-around seems like the best option so far, but screen resizing may cause a problem, and will likely require much more scripting than I want to do to achieve my goal. Being forced to use a monospace font is less than desirable - so not really an option.

I’ve also considered using a field within a field to accomplish this.

This definitely seems like a candidate for the next upgrade. It would surely improve the look of tables in general!

Try this:

if event.propertyName=='data':
    cname = 'Value2'
    cwidth = 10
    idx = event.newValue.getColumnIndex(cname)
    maxlen = max([len(str(s)) for s in event.newValue.getColumnAsList(idx)])
    cads = event.source.columnAttributesData
    idx = cads.getColumnIndex('name')
    try:
        row = list(cads.getColumnAsList(idx)).index(cname)
        spaces = max([0, int(cwidth-maxlen/2)])
        event.source.columnAttributesData = system.dataset.updateRow(cads, row, {'suffix': ' '*spaces})
    except:
        pass

Adjust cname and cwidth to suit. If your window is using scaling, it should work relatively well.