Results 1 to 3 of 3

Thread: Restrict size of QLineEdit

  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Restrict size of QLineEdit

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Restrict size of QLineEdit

    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).
    Last edited by wysota; 19th March 2007 at 17:27.

  3. #3
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Restrict size of QLineEdit

    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.

Similar Threads

  1. Resizing a QDialog to the content size
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2007, 09:16
  2. Replies: 3
    Last Post: 30th January 2007, 08:35
  3. Replies: 1
    Last Post: 24th October 2006, 17:40
  4. QTreeView font size not being set
    By forrestfsu in forum Qt Tools
    Replies: 2
    Last Post: 12th October 2006, 14:53
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.