An Observation and Question Regarding Gtk ColumnViewColumn set_fixed_width method

Having spent a few hours scratching various parts of my anatomy wondering why setting the width didn’t appear to do anything. I eventually realised the width units are ‘px’ and not characters (helpful to mention this in the docs).

My question is: does anyone know of a way to convert a character to number of pixels. The problem will be that the conversion is font and font size dependant.

I asking, is this a rabbet hole I want to disappear down or is there a better way.


SIzes are always in logical pixels, unless noted otherwise—typically in the API naming itself.

You can use Pango to determine the size of the “m” glyph and then multiply by the number of characters you want. But remember: fixing the size of a widget to a number of characters may break horribly when localisation is taken into account.

Thanks Emmanuele for responding your a star.

Ok I admit I have not read most of the documentation, not that it isn’t interesting and relevant just I could spend more time reading rather than doing. But thanks for the clarification.

The reason this came about is my ColumnView and ListView broke the window layout when they were empty. I really needed some way to at least have the layout looking correct in that situation. Setting fixed column widths achieved that simply. (an aside I used the set_placeholder for ListView, pity there isn’t something similar for ColumnView).

I already have function that scales the number of characters by a constant (derived by eye). So I’m thinking the constant could be an enum value selected when the language is set through configuration. That way at least something then exists to develop further.

Thanks I hadn’t entirely disregarded localisation but if my app goes in that direction then there is a there’s a whole legal tax framework to consider and not just language. The app then becomes a different beast altogether and way out of my frame of very mega capability.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.