PDA

View Full Version : Restrict size of QLineEdit



bruccutler
19th March 2007, 16:07
I'm struggling with the size of a simple QLineEdit. I'm entering a fixed size entry (IP address). I want the field to be no bigger than the size of the entry. I've searched through all the sizing stuff, but I simply need to say, set the size to the size of the mask and then leave it alone.

I'm sure this is simple, but I can't seem to find a simple solution.
- BRC

wysota
19th March 2007, 16:23
Try setting the horizontal size policy of the line edit to Fixed or Maximum.

Edit: Naaa.... I just noticed it doesn't work. I'll try to find a better solution.

Edit2: Looks like QLineEdit doesn't take into consideration the maximum length of input (if it is set of course) when calculating its sizeHint. You'd have to either subclass and calculate the sizeHint() properly or calculate the size and set it as the maximum size allowed for the widget (without subclassing).

bruccutler
19th March 2007, 16:31
Found my solution in the QFontMetrics. That's what I was looking for. I now get the font metrics from the QLineEdit, give the QFonMetrics the xxx.xxx.xxx string and calculate the size. Then I fix the size of this field to a fixed size.