Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Custom QWidget Keyboard first time click issue.


  • Lifetime Qt Champion

    @Arvind-K
    Hi
    What did
    qDebug() << "focus widget " << qApp->focusObject();
    report ?
    in the case where it dont type.



  • @mrjj

    i used qDebug() << "focus widget " << qApp->focusObject(); at button click event.

    it doesn't fire at first time . but at second time click on Button "a" i get "focus widget QPushButton(0x26bbc00, name= "Buttona")" log .

    i think at first time my keyboard widget doesn't get activate. after click on widget anywhere it gets activate and after that it works proper.

    how to solve this issue.?


  • Moderators

    Hi,

    from my experience, this behaviour comes from the focus shift,

    you click a button and than it gets the focus a and only than the clicked mechanimn works.

    IIRC, you can change that a couple of different ways.

    the following comes to my mind:

    • Chaning the signal from clicked to released
    • Subclassing QPushButton and manually emitting the pressed signal during focus in event


  • @J.Hilk

    Thank you for your reply.

    1. At the first time my Push button click event is not getting fired so released event is also not working.
    2. I have implemented focus in event but at first time its also not getting emitting.

  • Lifetime Qt Champion

    @Arvind-K
    Hi
    for my keyboard, I find it needed to have
    NoFocus for focusPolicy on the buttons or they steal focus from Lineedit.



  • still, the issue is pending. Please provide a solution.



  • It may be a silly question, does it happen with all the buttons of your keyboard?
    Are you sure that the first time you push on a button of your keyboard the slot keyboardHandler() gets called?



  • @JoZCaVaLLo

    Yes, it happens with all the buttons of a keyboard. slot keyboardHandler() does not get called for the first time. another thing I observed that when I called a keyboard on QPushbutton clicked event then keyboard works properly. this issue happens with QlineEdit Only.



  • I would call lineEditkeyboard->setLineEdit(line) only when the lineEdit gets the focus.
    In addition, in the setLineEdit(), I would call this->setFocusProxy(line). In order to avoid your keyboard to steal the focus from your linedit.



  • @JoZCaVaLLo
    @mrjj
    @J-Hilk
    @dheerendra
    one more thing to share when I called keyboard widget with a show() like
    lineEditkeyboard->setLineEdit(line);
    lineEditkeyboard->show();

    the keyboard works properly but when I called Keyboard like

    lineEditkeyboard->setLineEdit(line);
    lineEditkeyboard->setWindowModality(Qt::ApplicationModal);
    lineEditkeyboard->show();

    then I face the same issue of the first click.


  • Lifetime Qt Champion

    @Arvind-K
    hi, we need to find out what is happening.
    please do
    qDebug() << "focus widget " << qApp->focusObject();
    which tells us when you open the keyboard, who has focus.
    Meaning who will get the keys if u type.
    I think you have something that steals keyboard focus when u open the
    lineEditkeyboard



  • @mrjj

    as you said I have done same when keyboard widget is shown.
    output is

    DBG default: focus widget QLineEdit(0x227ca90, name = "lineEdit")

    lineEdit is Nothing but the QLineEdit on Keyboard widget.


  • Lifetime Qt Champion

    @Arvind-K
    Ok so it does have the focus when first click is not registered?



  • @mrjj

    Yes.
    after that when I click on Anywhere on Widget Nothing happen or no Any event gets called.


  • Lifetime Qt Champion

    @Arvind-K
    so the widget appear frozen for a moment ?
    Do you have any kind of loops in constructor or anything like that ?



  • @mrjj

    No, there is no Loop in the constructor or No Any other code only I have connected signal to Slot.

    Keyboard::Keyboard(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Keyboard)
    {
    ui->setupUi(this);

    this->setWindowFlags(Qt::WindowStaysOnTopHint);
    connect ( ui->Buttonq, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonw, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttone, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonr, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttont, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttony, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonu, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttoni, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttono, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonp, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    
    connect ( ui->Buttona, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttons, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttond, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonf, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttong, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonh, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonj, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonk, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonl, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonz, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonx, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonc, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonv, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonb, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonn, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Buttonm, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button0, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button1, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button2, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button3, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button4, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button5, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button6, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button7, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button8, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->Button9, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    connect ( ui->space, SIGNAL( clicked() ), this, SLOT( keyboardHandler() ) );
    
    outputText = "";
    shift = false;
    

    }


  • Lifetime Qt Champion

    @Arvind-K
    ok. when this situation is happening.
    Does the buttons show activated effect ?
    I mean can u see u pres them or anything ?



  • @mrjj

    As I mentioned Previously when I set WindowModality of Keyboard widget to QApplicationModal I face this First Click issue otherwise it works fine. but if I didn't set windowModality then Keyboard goes back to the parent widget.

    **lineEditkeyboard->setWindowModality(Qt::ApplicationModal); **


  • Lifetime Qt Champion

    Hmm.
    The code looks ok fine and i cant see any reason for
    QApplicationModal to cause this effect but
    it could be a bug in Qt.



  • @mrjj

    I can't see press button effect for the first time.


  • Lifetime Qt Champion

    @Arvind-K
    Ok, then it seems its stuck for a moment in the event loop.
    Im not sure what to do about that.
    setWindowModality(Qt::ApplicationModal) must use a local even loop to make
    it modal so might be a but with this or something i dont see in the code.


Log in to reply