ignore shift to move between edit text
-
my problem is with a code scanner and using focus with keypressevent
i have two edits and my keyboard event is like thisvoid 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 toolike here B should have been on second edit
-
my problem is with a code scanner and using focus with keypressevent
i have two edits and my keyboard event is like thisvoid 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 toolike here B should have been on second edit
-
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? -
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?@VRonin my scenario is like this -
- I have a barcode scanner connect to laptop with usb as are those in markets.
- 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 .
-
@VRonin my scenario is like this -
- I have a barcode scanner connect to laptop with usb as are those in markets.
- 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 .
@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 yourkeyPressEvent
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..
-
@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 yourkeyPressEvent
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..
-
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) -
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) -
@mrjj i will make some debugging now, but is not about that cause i commented ui->leInformation->KeyPressEvent(event); and is the same
@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#installEventFilterIts hard to suggest what to do when we dont really know why input makes it focus next control.
-
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?
@rest said in ignore shift to move between edit text:
Qt::ShiftModifier
if(event->modifiers() & Qt::ShiftModifier){...}
-
@rest
Be careful: I'm thinking you will get one event for just the SHIFT press, and thenQt::ShiftModifier
will also still be true for the event which arrives for theB
.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?
-
@rest
Be careful: I'm thinking you will get one event for just the SHIFT press, and thenQt::ShiftModifier
will also still be true for the event which arrives for theB
.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?
-
@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
-
@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
-
@rest
But aren't you saying the "key presses for the barcode" are for each letter? When the second key arrives inlePath
(it has the focus, and it's no longer empty), won't your code send it toleInformation
?