Results 1 to 7 of 7

Thread: How to limit the size of QLineEdit?

  1. #1
    Join Date
    Aug 2009
    Location
    Saudi Arabia - Buraidah
    Posts
    48
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to limit the size of QLineEdit?

    Hi,

    I want to limit the size of QLineEdit to only 3 chars, how to do that?

    Notice that the user can change the font of QLineEdit so I need it to resize to show only 3 chars in user selected font size?

    Thanks,
    Mohammad
    http://brainstorm.ubuntu.com/idea/24714/image/1/
    The Linux Counter Project - user number # 497262
    The Ubuntu Counter Project - user number # 29025

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to limit the size of QLineEdit?

    Use:
    Qt Code:
    1. QLineEdit::setMaxLength(3);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to yogeshgokul for this useful post:

    MIH1406 (3rd June 2010)

  4. #3
    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: How to limit the size of QLineEdit?

    Quote Originally Posted by MIH1406 View Post
    I want to limit the size of QLineEdit to only 3 chars, how to do that?
    Reimplement sizeHint().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    MIH1406 (3rd June 2010)

  6. #4
    Join Date
    Aug 2009
    Location
    Saudi Arabia - Buraidah
    Posts
    48
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to limit the size of QLineEdit?

    yogeshgokul:
    setMaxLength() // Does not change the width of the QLineEdit

    wysota:
    What can I do with sizeHint()?

    Thanks,
    MIH1406
    http://brainstorm.ubuntu.com/idea/24714/image/1/
    The Linux Counter Project - user number # 497262
    The Ubuntu Counter Project - user number # 29025

  7. #5
    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: How to limit the size of QLineEdit?

    Quote Originally Posted by MIH1406 View Post
    wysota:
    What can I do with sizeHint()?
    Whatever you want. Look at the sourcecode for QLineEdit::sizeHint() and in the subclass adjust it accordingly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    MIH1406 (1st October 2009)

  9. #6
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to limit the size of QLineEdit?

    Or read the documentation.

    Best Regards
    NoRulez

  10. The following user says thank you to NoRulez for this useful post:

    MIH1406 (1st October 2009)

  11. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to limit the size of QLineEdit?

    Quote Originally Posted by NoRulez View Post
    Or read the documentation.
    Only one line documentation

  12. The following user says thank you to yogeshgokul for this useful post:

    MIH1406 (3rd June 2010)

Similar Threads

  1. Limit window size to certain ranges
    By markwestcott in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 10:50
  2. QVBoxLayout width size limit
    By QPlace in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 17:41
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13
  4. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 18:57
  5. Restrict size of QLineEdit
    By bruccutler in forum Newbie
    Replies: 2
    Last Post: 19th March 2007, 17:31

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.