[Qt-interest] QLineEdit sizeHint question.

phil prentice philp.cheer at talktalk.net
Wed Jan 20 09:40:19 CET 2010


Hi
  I'm slowly porting over a Motif X11 application to QT.  The old application 
used to define a line edit window of a fixed size.  So if the width was set 
to 6 then the line edit window would be set to 6 characters.  So I am trying 
to use sizeHint() to achieve the same result. i.e.

size.setWidth(fontMetrics().maxWidth() * 6);

The result I get is not always consistent, but its always smaller.  For 
example a width of six only gives me enough room for 4 characters.  I guess 
part of the problem is the frame size + any padding.  I tried looking at the 
documentation but could not fine anything that might help me take account of 
those.

One way might be to create the widget with a temporary string set to the 
character count...but is there a better way?

I know it will also depend on the character width..but I'm trying to use a 
font of constant width.

Any ideas?

Thanks




More information about the Qt-interest-old mailing list