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. ignore shift to move between edit text

ignore shift to move between edit text

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 4 Posters 3.4k 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.
  • R Offline
    R Offline
    rest
    wrote on 12 Apr 2018, 13:17 last edited by VRonin 4 Dec 2018, 14:03
    #1

    my problem is with a code scanner and using focus with keypressevent
    i have two edits and my keyboard event is like this

    
        void CWidget::keyPressEvent(QKeyEvent *event)
        {
          if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
          {
            ui->leInformation->setFocus();
            ui->leInformation->setFocusPolicy(Qt::StrongFocus);
            ui->leInformation->KeyPressEvent(event);
          }
          else
          {
            ui->lePath->setFocus();
            ui->lePath->setFocusPolicy(Qt::StrongFocus);
            ui->lePath->KeyPressEvent(event);
          }
        }
    
    

    if i scan a code with digits and lowercase letters everything is fine.
    if i scan with uppercase letters some of text goes to the other edit
    because of the way uppercase are managed with shift, shift changing between the two edits too. how i can make them not change between those too alt text like here B should have been on second edit

    R 1 Reply Last reply 12 Apr 2018, 13:17
    0
    • R rest
      12 Apr 2018, 13:17

      my problem is with a code scanner and using focus with keypressevent
      i have two edits and my keyboard event is like this

      
          void CWidget::keyPressEvent(QKeyEvent *event)
          {
            if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
            {
              ui->leInformation->setFocus();
              ui->leInformation->setFocusPolicy(Qt::StrongFocus);
              ui->leInformation->KeyPressEvent(event);
            }
            else
            {
              ui->lePath->setFocus();
              ui->lePath->setFocusPolicy(Qt::StrongFocus);
              ui->lePath->KeyPressEvent(event);
            }
          }
      
      

      if i scan a code with digits and lowercase letters everything is fine.
      if i scan with uppercase letters some of text goes to the other edit
      because of the way uppercase are managed with shift, shift changing between the two edits too. how i can make them not change between those too alt text like here B should have been on second edit

      R Offline
      R Offline
      rest
      wrote on 12 Apr 2018, 13:17 last edited by
      #2

      0_1523539075426_dsds.PNG

      R 1 Reply Last reply 12 Apr 2018, 13:44
      0
      • R rest
        12 Apr 2018, 13:17

        0_1523539075426_dsds.PNG

        R Offline
        R Offline
        rest
        wrote on 12 Apr 2018, 13:44 last edited by
        #3

        help please i tried a lot and nothing

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 12 Apr 2018, 14:10 last edited by VRonin 4 Dec 2018, 14:10
          #4

          I think there's a better way to do this than intercepting keys.
          What is the behaviour you want?
          What I see here is:
          The first key goes into the line you are focusing, the second key goes on the other line, the third key on the original line and so on. is it corrrect?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          R 1 Reply Last reply 12 Apr 2018, 17:24
          0
          • V VRonin
            12 Apr 2018, 14:10

            I think there's a better way to do this than intercepting keys.
            What is the behaviour you want?
            What I see here is:
            The first key goes into the line you are focusing, the second key goes on the other line, the third key on the original line and so on. is it corrrect?

            R Offline
            R Offline
            rest
            wrote on 12 Apr 2018, 17:24 last edited by rest 4 Dec 2018, 17:26
            #5

            @VRonin my scenario is like this -

            1. I have a barcode scanner connect to laptop with usb as are those in markets.
            2. when i scan first bar code to be inserted in first edit when i scan another barcode to go in second edit.

            But my problem now is like this each time i scan a barcode who contains a uppercase letter the part of code until the uppercase letter goes where it should be and the rest goes to the other edit is like im using, but other thing i saw is when i press shift he moves me between edit like i m using tab .

            J 1 Reply Last reply 12 Apr 2018, 17:41
            0
            • R rest
              12 Apr 2018, 17:24

              @VRonin my scenario is like this -

              1. I have a barcode scanner connect to laptop with usb as are those in markets.
              2. when i scan first bar code to be inserted in first edit when i scan another barcode to go in second edit.

              But my problem now is like this each time i scan a barcode who contains a uppercase letter the part of code until the uppercase letter goes where it should be and the rest goes to the other edit is like im using, but other thing i saw is when i press shift he moves me between edit like i m using tab .

              J Offline
              J Offline
              JonB
              wrote on 12 Apr 2018, 17:41 last edited by
              #6

              @rest
              At some level I think you're telling us that your bar code scanner generates key events for the characters it meets?...

              I guess SHIFT itself raises a CWidget::keyPressEvent? So (given what you're doing), you better make your keyPressEvent code look to see if its the SHIFT key and not do the focus swap in that case. Your focus swap code is what is causing it to act like TAB.

              I suspect apart from that that your approach is wrong, but the above is to answer your question as to why it behaves as it does..

              R 1 Reply Last reply 12 Apr 2018, 17:54
              1
              • J JonB
                12 Apr 2018, 17:41

                @rest
                At some level I think you're telling us that your bar code scanner generates key events for the characters it meets?...

                I guess SHIFT itself raises a CWidget::keyPressEvent? So (given what you're doing), you better make your keyPressEvent code look to see if its the SHIFT key and not do the focus swap in that case. Your focus swap code is what is causing it to act like TAB.

                I suspect apart from that that your approach is wrong, but the above is to answer your question as to why it behaves as it does..

                R Offline
                R Offline
                rest
                wrote on 12 Apr 2018, 17:54 last edited by
                #7

                @JonB so how you think i should approach this? i still think i need the keypressevent .. i don't have so much experience with working with qt and events

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 12 Apr 2018, 17:59 last edited by
                  #8

                  Hi
                  Did you use debugger and check what key combination that makes it
                  "tab" to next edit ?
                  I wondering if the jump happens when u pass the key to
                  ui->leInformation->KeyPressEvent(event);
                  (then we can maybe do different, like remove shift)

                  R 1 Reply Last reply 12 Apr 2018, 18:01
                  0
                  • mrjjM mrjj
                    12 Apr 2018, 17:59

                    Hi
                    Did you use debugger and check what key combination that makes it
                    "tab" to next edit ?
                    I wondering if the jump happens when u pass the key to
                    ui->leInformation->KeyPressEvent(event);
                    (then we can maybe do different, like remove shift)

                    R Offline
                    R Offline
                    rest
                    wrote on 12 Apr 2018, 18:01 last edited by
                    #9

                    @mrjj i will make some debugging now, but is not about that cause i commented ui->leInformation->KeyPressEvent(event); and is the same

                    mrjjM 1 Reply Last reply 12 Apr 2018, 18:10
                    0
                    • R rest
                      12 Apr 2018, 18:01

                      @mrjj i will make some debugging now, but is not about that cause i commented ui->leInformation->KeyPressEvent(event); and is the same

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 12 Apr 2018, 18:10 last edited by
                      #10

                      @rest
                      if you dont forward the keys at all , it still jumps ?
                      Ok, it sounds like the input trigger key navigation.

                      I assume you are using an USB scanner in hid keyboard mode.

                      You might want to install event filter on Application to find out what is going on.
                      http://doc.qt.io/qt-5/qobject.html#installEventFilter

                      https://stackoverflow.com/questions/26368659/qwidget-how-to-receive-keypressevent-inside-child-widgets

                      Its hard to suggest what to do when we dont really know why input makes it focus next control.

                      1 Reply Last reply
                      2
                      • R Offline
                        R Offline
                        rest
                        wrote on 12 Apr 2018, 18:22 last edited by
                        #11

                        so i made some debugging and when shift is pressed he gets inside my if and changes focus
                        alt text
                        0_1523557300643_dsdsdsdsds.PNG

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rest
                          wrote on 12 Apr 2018, 18:23 last edited by
                          #12

                          but witch one of the variables gets me the key pressed? i tried something like this !event->key() == Qt::ShiftModifier and doesnt work, there is another way to check?

                          mrjjM 1 Reply Last reply 12 Apr 2018, 18:24
                          0
                          • R rest
                            12 Apr 2018, 18:23

                            but witch one of the variables gets me the key pressed? i tried something like this !event->key() == Qt::ShiftModifier and doesnt work, there is another way to check?

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 12 Apr 2018, 18:24 last edited by
                            #13

                            @rest said in ignore shift to move between edit text:

                            Qt::ShiftModifier

                            if(event->modifiers() & Qt::ShiftModifier){...}

                            1 Reply Last reply
                            2
                            • R Offline
                              R Offline
                              rest
                              wrote on 12 Apr 2018, 18:36 last edited by
                              #14

                              @mrjj thank you so much, i will try everything and see what works

                              J 1 Reply Last reply 12 Apr 2018, 18:51
                              0
                              • R rest
                                12 Apr 2018, 18:36

                                @mrjj thank you so much, i will try everything and see what works

                                J Offline
                                J Offline
                                JonB
                                wrote on 12 Apr 2018, 18:51 last edited by
                                #15

                                @rest
                                Be careful: I'm thinking you will get one event for just the SHIFT press, and then Qt::ShiftModifier will also still be true for the event which arrives for the B.

                                I don't get the whole intention of what you're trying to achieve with your code. You decide where input is to go based on:

                                if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
                                

                                Why? What's the logic here? What's the idea of switching focus here?

                                R 1 Reply Last reply 12 Apr 2018, 18:56
                                1
                                • J JonB
                                  12 Apr 2018, 18:51

                                  @rest
                                  Be careful: I'm thinking you will get one event for just the SHIFT press, and then Qt::ShiftModifier will also still be true for the event which arrives for the B.

                                  I don't get the whole intention of what you're trying to achieve with your code. You decide where input is to go based on:

                                  if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
                                  

                                  Why? What's the logic here? What's the idea of switching focus here?

                                  R Offline
                                  R Offline
                                  rest
                                  wrote on 12 Apr 2018, 18:56 last edited by
                                  #16

                                  @JonB if i scanned a barcode means that focus is on first edit and he is not empty means i should change focus on second edit for scanning there, this is what i thought i don t have so much experience on this i don t really know how i can make this work

                                  mrjjM J 2 Replies Last reply 12 Apr 2018, 18:59
                                  0
                                  • R rest
                                    12 Apr 2018, 18:56

                                    @JonB if i scanned a barcode means that focus is on first edit and he is not empty means i should change focus on second edit for scanning there, this is what i thought i don t have so much experience on this i don t really know how i can make this work

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 12 Apr 2018, 18:59 last edited by
                                    #17

                                    @rest
                                    How do you know first barcode data is 100% received ?
                                    Since it comes key pr key. Is there an end of input char ?

                                    1 Reply Last reply
                                    0
                                    • R rest
                                      12 Apr 2018, 18:56

                                      @JonB if i scanned a barcode means that focus is on first edit and he is not empty means i should change focus on second edit for scanning there, this is what i thought i don t have so much experience on this i don t really know how i can make this work

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 12 Apr 2018, 19:01 last edited by
                                      #18

                                      @rest
                                      But aren't you saying the "key presses for the barcode" are for each letter? When the second key arrives in lePath (it has the focus, and it's no longer empty), won't your code send it to leInformation?

                                      R 1 Reply Last reply 12 Apr 2018, 19:09
                                      2
                                      • R Offline
                                        R Offline
                                        rest
                                        wrote on 12 Apr 2018, 19:06 last edited by
                                        #19

                                        No, i dont have something like that .. i don t know how to check this.. gets so difficult. first i had just one edit text and everything worked fine..

                                        1 Reply Last reply
                                        0
                                        • J JonB
                                          12 Apr 2018, 19:01

                                          @rest
                                          But aren't you saying the "key presses for the barcode" are for each letter? When the second key arrives in lePath (it has the focus, and it's no longer empty), won't your code send it to leInformation?

                                          R Offline
                                          R Offline
                                          rest
                                          wrote on 12 Apr 2018, 19:09 last edited by
                                          #20

                                          @JonB what you mean with second key? everything is well until the uppercase gets in, if i scan only digits everything is fine for both edits

                                          1 Reply Last reply
                                          0

                                          1/22

                                          12 Apr 2018, 13:17

                                          • Login

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