Results 1 to 6 of 6

Thread: QLineEdit default text

  1. #1
    Join Date
    Dec 2009
    Posts
    41
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QLineEdit default text

    Hi !

    I am using a QLineEdit and would like to have a default text when the QLineEdit is empty. Usually this text is grey and in italic (like in QtCreator). But the only thing I have found to perform this is setPlaceHolderText() but the documentation says it has been introduced in Qt 4.7...

    Any idea ? Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit default text

    You will need to subclas QLIneEdit.
    On focusIn and focusOut events you will have set / clear the gray text.
    And I guess making text gray is not that difficult

  3. #3
    Join Date
    Dec 2009
    Posts
    41
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QLineEdit default text

    OK, I just wondered if there was something quicker

  4. #4
    Join Date
    Nov 2009
    Location
    Internet
    Posts
    11
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit default text

    I think either you can use event filters: Events and Event Filters

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit default text

    You can check on qt.gitorious.com the sources and find how Trolls did it in Qt 4.7's QLineEdit :]
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Oct 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QLineEdit default text

    how did you solve your problem? I meet this too.

Similar Threads

  1. Replies: 4
    Last Post: 6th April 2010, 00:46
  2. QLineEdit text orientation
    By emrares in forum Qt Programming
    Replies: 7
    Last Post: 15th September 2009, 06:25
  3. Default delegate displays empty QLineEdit?
    By andy.fillebrown in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2009, 13:13
  4. QLineEdit and background text
    By SnarlCat in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2009, 22:17
  5. Text before editting on QLineEdit
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2008, 15:51

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.