Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom QWidget Keyboard first time click issue.
Forum Update on Monday, May 27th 2025

Custom QWidget Keyboard first time click issue.

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 5 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 13 Jul 2018, 08:30 last edited by
    #9

    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

    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    A 1 Reply Last reply 17 Jul 2018, 07:11
    0
    • J J.Hilk
      13 Jul 2018, 08:30

      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
      A Offline
      A Offline
      Arvind K
      wrote on 17 Jul 2018, 07:11 last edited by
      #10

      @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.
      M 1 Reply Last reply 17 Jul 2018, 07:13
      0
      • A Arvind K
        17 Jul 2018, 07:11

        @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.
        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 17 Jul 2018, 07:13 last edited by
        #11

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

        1 Reply Last reply
        1
        • A Offline
          A Offline
          Arvind K
          wrote on 2 Aug 2018, 03:39 last edited by
          #12

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

          1 Reply Last reply
          -1
          • D Offline
            D Offline
            deleted372
            wrote on 2 Aug 2018, 08:04 last edited by
            #13

            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?

            A 1 Reply Last reply 2 Aug 2018, 08:55
            0
            • D deleted372
              2 Aug 2018, 08:04

              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?

              A Offline
              A Offline
              Arvind K
              wrote on 2 Aug 2018, 08:55 last edited by
              #14

              @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.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                deleted372
                wrote on 2 Aug 2018, 09:07 last edited by
                #15

                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.

                A 1 Reply Last reply 2 Aug 2018, 09:46
                0
                • D deleted372
                  2 Aug 2018, 09:07

                  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.

                  A Offline
                  A Offline
                  Arvind K
                  wrote on 2 Aug 2018, 09:46 last edited by
                  #16

                  @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.

                  M 1 Reply Last reply 2 Aug 2018, 10:08
                  0
                  • A Arvind K
                    2 Aug 2018, 09:46

                    @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.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 2 Aug 2018, 10:08 last edited by
                    #17

                    @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

                    A 1 Reply Last reply 3 Aug 2018, 05:49
                    0
                    • M mrjj
                      2 Aug 2018, 10:08

                      @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

                      A Offline
                      A Offline
                      Arvind K
                      wrote on 3 Aug 2018, 05:49 last edited by
                      #18

                      @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.

                      M 1 Reply Last reply 3 Aug 2018, 05:57
                      0
                      • A Arvind K
                        3 Aug 2018, 05:49

                        @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.

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 3 Aug 2018, 05:57 last edited by
                        #19

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

                        A 1 Reply Last reply 3 Aug 2018, 05:59
                        0
                        • M mrjj
                          3 Aug 2018, 05:57

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

                          A Offline
                          A Offline
                          Arvind K
                          wrote on 3 Aug 2018, 05:59 last edited by
                          #20

                          @mrjj

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

                          M 1 Reply Last reply 3 Aug 2018, 06:02
                          0
                          • A Arvind K
                            3 Aug 2018, 05:59

                            @mrjj

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

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 3 Aug 2018, 06:02 last edited by
                            #21

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

                            A 1 Reply Last reply 3 Aug 2018, 06:31
                            0
                            • M mrjj
                              3 Aug 2018, 06:02

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

                              A Offline
                              A Offline
                              Arvind K
                              wrote on 3 Aug 2018, 06:31 last edited by
                              #22

                              @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;
                              

                              }

                              M 1 Reply Last reply 3 Aug 2018, 06:43
                              0
                              • A Arvind K
                                3 Aug 2018, 06:31

                                @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;
                                

                                }

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 3 Aug 2018, 06:43 last edited by
                                #23

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

                                A 1 Reply Last reply 3 Aug 2018, 10:18
                                0
                                • A Offline
                                  A Offline
                                  Arvind K
                                  wrote on 3 Aug 2018, 06:50 last edited by
                                  #24

                                  @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); **

                                  M 1 Reply Last reply 3 Aug 2018, 06:55
                                  0
                                  • A Arvind K
                                    3 Aug 2018, 06:50

                                    @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); **

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 3 Aug 2018, 06:55 last edited by
                                    #25

                                    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.

                                    1 Reply Last reply
                                    0
                                    • M mrjj
                                      3 Aug 2018, 06:43

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

                                      A Offline
                                      A Offline
                                      Arvind K
                                      wrote on 3 Aug 2018, 10:18 last edited by
                                      #26

                                      @mrjj

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

                                      M 1 Reply Last reply 3 Aug 2018, 10:21
                                      0
                                      • A Arvind K
                                        3 Aug 2018, 10:18

                                        @mrjj

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

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 3 Aug 2018, 10:21 last edited by
                                        #27

                                        @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.

                                        1 Reply Last reply
                                        0

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved