Results 1 to 7 of 7

Thread: Is there focus event for line edit?

  1. #1
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Is there focus event for line edit?

    Hi,
    I have a form which shows the line edit widget. Now my problem is i want to show the virtual keyboard whenever user clicks on the line edit. Means whenever user highlights it. But i couldn't find any event other than
    "textChanged" and "textEdit" . So how to achieve this? Any pointer to the solution will help.

  2. #2
    Join Date
    Jan 2009
    Location
    Czech Republic
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there focus event for line edit?


  3. #3
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there focus event for line edit?

    I tried this and also installed the event filter

    exportData::exportData(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::exportData)
    {
    ui->setupUi(this);
    ui->edtFileName->installEventFilter(ui->edtFileName);
    keyBoard= new KeyboardEntryImpl(ui->edtFileName,NULL);
    }

    But in the bool exportData::eventFilter(QObject *obj, QEvent *ev)
    {
    }

    I am not able to receive any event.

    If i change ui->edtFileName->installEventFilter(ui->edtFileName); to ui->edtFileName->installEventFilter(this);Then i am getting every event that's being generated for the Main window. But i am only intersted in events when Line edit get the focus.

  4. #4
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there focus event for line edit?

    ui->edtFileName->installEventFilter(ui->edtFileName);
    keyBoard= new KeyboardEntryImpl(ui->edtFileName,NULL);
    }

    But in the bool exportData::eventFilter(QObject *obj, QEvent *ev)
    {
    }
    You made a mistake here. You have install the event filter of edtFileName to edtFileName. If you want to use event filter in "exportData" class
    then you should use function in this way
    Qt Code:
    1. exportData->installEventFilter(ui->editFileName)
    To copy to clipboard, switch view to plain text mode 

    Now your code
    bool exportData::eventFilter(QObject *obj, QEvent *ev)
    {
    }

    should work fine

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is there focus event for line edit?

    Quote Originally Posted by navi1084 View Post
    You made a mistake here. You have install the event filter of edtFileName to edtFileName. If you want to use event filter in "exportData" class
    then you should use function in this way
    Qt Code:
    1. exportData->installEventFilter(ui->editFileName)
    To copy to clipboard, switch view to plain text mode 
    It has to be
    Qt Code:
    1. installEventFilter(ui->editFileName)
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is there focus event for line edit?

    It didn't worked either way as mentioned in the upper two replies. But i got it worked just wanted to share that with you guys

    I have to call ui->edtFileName->installEventFilter(ui->edtFileName); only because otherwise no event was coming to the event filter if i did

    installEventFilter(ui->editFileName) or exportData->installEventFilter(ui->editFileName)
    and in event filter i am doing this

    bool exportData::eventFilter(QObject *obj, QEvent *ev)
    {
    if(obj == ui->edtFileName)
    {
    if(ev->type() == QEvent::MouseButtonPress )
    //if(ev->type() == QEvent::FocusIn )
    {
    keyBoard->show();
    ui->edtFileName->setFocus();
    }
    }
    return false;
    }

    Now i am capturing the mouse press event for the line edit object. But my only worry is that unnes=cessary control comes to this function on every event(apart from line edit events,which i wanted to do).

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Is there focus event for line edit?

    Yeah, that was too fast. The right syntax should be
    Qt Code:
    1. ui->edtFileName->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 
    in the c-tor of exportData.
    Now i am capturing the mouse press event for the line edit object. But my only worry is that unnes=cessary control comes to this function on every event(apart from line edit events,which i wanted to do).
    That's the sense of an event filter. No problem. You can alternative, instead of returning false, call the base class event handler.

Similar Threads

  1. line edit focus
    By addu in forum Qt Programming
    Replies: 3
    Last Post: 16th July 2009, 15:39
  2. How to use the content of line Edit in different forms
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2009, 05:55
  3. line edit value change with slider
    By jjbabu in forum Qt Tools
    Replies: 1
    Last Post: 22nd September 2007, 07:02
  4. mask line edit
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 3rd July 2007, 10:27
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

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.