qt app that takes in textedit barcode scanned, how to change focus between two fields

一笑奈何 提交于 2019-12-24 20:13:10

问题


So for me the plan is like this:

I scan a barcode, it gets in first textedit; I scan another barcode, it gets in the second textedit,
in this case i use focus and keyboard event.

my problem is when i scan first code it is fine but when I scan the second code, some of letters go to second texedit some go to first texedit. I don't understand what is the problem here is my code

void CWidget::keyPressEvent(QKeyEvent *event)
{
  if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
  {
    ui->leInformation->setFocus(); //leInformation second edit 
    ui->leInformation->setFocusPolicy(Qt::StrongFocus);
    ui->leInformation->KeyPressEvent(event);
  }
  else
  {
    ui->lePath->setFocus(); //lePath - first edit text, first code scanned //goes here
    ui->lePath->setFocusPolicy(Qt::StrongFocus);
    ui->lePath->KeyPressEvent(event);
  }
}

like is a strange think cause sometimes works sometimes no, if both codes scanned have digits they work but if the second scanned code has uppercase letters they go from the first uppercase letters they are wrote to first edit. but if they are lowercase they are fine again. I m thinking it is a problem with keyboard event how they deal with uppercase. somehow maybe with shift, and they change between two edits. if there is someone who has an idea on how i can properly write that keyboard event, please help thanks

here B should have been on the second. I'm being sure on how uppercase are being entered on keyboard event is about shift + letter and shift moves you to the other edit but how i can change this

来源:https://stackoverflow.com/questions/49796174/qt-app-that-takes-in-textedit-barcode-scanned-how-to-change-focus-between-two-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!