Results 1 to 7 of 7

Thread: clear button for line edit

  1. #1

    Default clear button for line edit

    Hii all..

    Can I know how to add a clear button to a QLineEdit ?

    Thank You

    Jayakrishna Reddy

  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: clear button for line edit


  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Angry Re: clear button for line edit

    Hi, I guess you have a designer. If so, just add a button from the designer and just connect it to a slot as the following;

    Qt Code:
    1. connect( yourClearButton,
    2. SIGNAL(clicked()),
    3. this,
    4. SLOT(clearButtonClickedSlot()) );
    To copy to clipboard, switch view to plain text mode 

    and just implement the SLOT

    Qt Code:
    1. void Foo::clearButtonClickedSlot()
    2. {
    3. mUi->yourLineEdit->setText("");
    4. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: clear button for line edit

    Quote Originally Posted by zgulser View Post
    Hi, I guess you have a designer. If so, just add a button from the designer and just connect it to a slot as the following;

    Qt Code:
    1. connect( yourClearButton,
    2. SIGNAL(clicked()),
    3. this,
    4. SLOT(clearButtonClickedSlot()) );
    To copy to clipboard, switch view to plain text mode 

    and just implement the SLOT

    Qt Code:
    1. void Foo::clearButtonClickedSlot()
    2. {
    3. mUi->yourLineEdit->setText("");
    4. }
    To copy to clipboard, switch view to plain text mode 
    in this case you can simply use one connection
    Qt Code:
    1. connect( yourClearButton,
    2. SIGNAL(clicked()),
    3. mUi->yourLineEdit,
    4. SLOT(clear()) );
    To copy to clipboard, switch view to plain text mode 


    but I think author needs clear-button like aamer4yu suggested.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: clear button for line edit

    Oh I didn't know the clear thing..you're right.

    By the way, right about the last comment of yours as well I guess.

  6. #6

    Default Re: clear button for line edit

    Sorry..that is not the case. I am asking about how to add a clear button to a QLineEdit using cascading style sheets. So that I can display the clear button on the lineedit in the hover state.

  7. #7
    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: clear button for line edit

    You will need to make your custom widget.
    Also the link I gave before,, the code link seems to be invalid now...

Similar Threads

  1. Replies: 2
    Last Post: 10th November 2009, 07:17
  2. QLineEdit: with builtin clear button, how to
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2009, 21:05
  3. Line edit and push button
    By dela in forum Newbie
    Replies: 1
    Last Post: 10th December 2008, 17:10

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.