Results 1 to 4 of 4

Thread: line edit focus

  1. #1
    Join Date
    May 2009
    Posts
    129

    Default line edit focus

    I have set the line edit text as default by "Dial number"

    When i pressing the keys in keyboard ,then i am clearing the lineedit text and inserting the pressed key value in line edit..

    if i set lineEdit in setfocusby default..

    that time any key events is not uptating ..

    if diable the forucs for line edit.. key event are updating..

    Sample code..

    Qt Code:
    1. ui.lineEdit.setText("Dial Number")
    2.  
    3. void MainWindow::keyPressEvent(QKeyEvent *e)
    4. {
    5. switch(e->key)
    6. {
    7. case Key_0 :
    8. if(ui.lineEdit.Text == "Dial Number")
    9. {
    10. ui.lineEdit.clear }
    11. ui.lineEdit.insert("0");
    12. break;
    13. case Key_1 :
    14. if(ui.lineEdit.Text == "Dial Number")
    15. {
    16. ui.lineEdit.clear }
    17. ui.lineEdit.insert("1");
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Then i overrided the QLineEdit KeyPressEvent.

    Qt Code:
    1. class Con_Main : public QLineEdit
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Con_Main(QWidget *parent = 0);
    7. void keyPressEvent(QKeyEvent *e);
    8. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Con_Main::Con_Main(QWidget *parent = 0):QLineEdit(parent)
    2. {
    3. }
    4. void Con_Main::keyPressEvent(QKeyEvent *e)
    5. {
    6. // e->ignore();
    7. QMessageBox::information(0,"",QString("Con_main"));
    8. }
    To copy to clipboard, switch view to plain text mode 
    I have doubt at KeyPressEvent to over ride this method, have to ignore the event .what i have to do here..

    And it is giving the
    error: default argument given for parameter 1 of `Con_Main::Con_Main(QWidget*)'
    error: after previous specification in `Con_Main::Con_Main(QWidget*)'
    Please help me

    Thanks

    Yuaraj R
    Last edited by jpn; 16th July 2009 at 15:53. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: line edit focus

    How about using focusInEvent() and focusOutEvent() for clearing/restoring the place holder text? This is the way it traditionally works for example in browsers' search boxes.
    J-P Nurmi

  3. #3
    Join Date
    May 2009
    Posts
    129

    Default Re: line edit focus

    I am using the Keypressevent.

    i am asking what mistake i ahve done in my code.

    Thanks

    Yuvaraj R

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: line edit focus

    As for the compilation error, remove the default parameter value in your .cpp file. You already declared it in the .h file:
    Qt Code:
    1. Con_Main::Con_Main(QWidget *parent = 0):QLineEdit(parent) // <-- remove "= 0"
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 23:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 14:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 10:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 19:42

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.