I don't think there is a reliable cross-platform solution that covers all possible variations of font name and font size.
I would had no problems to use 2 complete different solutions, one for Windows and one for Linux. And it would be enough, if it worked for "a couple of common fonts" (like I used in my examples) in "normal" sizes. But I learned, that this is difficult...
How often do you actually need to change the combobox font from its Parent's value? I would just go for a routine that gives reliable results for a chosen font specification, and then leave the font unchanged.
On Windows I never had the idea to change the Default Fonts, because I was always satisfied with them. But on Linux I'm absolutely not satisfied with them. So there in many cases I changed / will change Fonts or their sizes to test them for a while, if I like this more or less. And just now I'm writing a new program with a couple of ComboBoxes and it would have been smart, if I had a function to compute the needed width automatically. But it's not worth to spend too much effort for this - I had hoped that it would be easier...
The point of the MulDiv line was to adapt the code for any possible monitor that might run the code. For any one given monitor (e. g. your monitor), obviously its PixelsPerInch value is a constant, and in your case the calculated "width" does not need scaling, as it happens.
Yes, I only replaced the MulDiv line temporarily with a const to make testing easier.
Windows seems to work when a size-dependent margin is added (Combobox.Canvas.TextWidth('M')) in addition to a small constant offset (2 pixels, which of course must be scaled to the screen resolution: ScaleX(2, 96) where 96 is the unscaled resolution ).
I made a test on Windows 7 and added ACombobox.Canvas.TextWidth('M') plus a const 'MD' additionally to AComboBox.Canvas.TextWidth(AComboBox.Items[]).
For 'Times New Roman' with Height=12 I needed MD=
16, for Height=22 I needed MD=
10 and for Height=30 I needed MD=
6. So unfortunately it does not work.
Linux qt is almost perfect, a constant margin of 8 pixels (to be scaled) seems to be sufficient
Linux gkt2 is the worst...
But I also guess that when the user changes themes in qt or gtk2 there will be new values again.
...
So, optimizing this is wasted time... Add ample of margin, and focus on something else...
I'm on gtk2. I agree, I give up. It's not worth to spend more effort for this.
Thanks again to both of you for your suggestions and trying to help me. And again I learned a couple of new things :-)