Unsolved Get physical key events
-
QT application is developed based on Embedded Linux. The device is non touch screen, using Weston. Press the button to report the event normally, but the application can't get the button event. Which direction should we start to solve this situation?
Thanks!
-
-
@jsulm
the phone key ,like the Nokia phone keys -
@jsulm
I have used the following procedure to test:Widget::Widget(QWidget *parent) : QWidget(parent) { setFocusPolicy(Qt::StrongFocus); setFixedSize(800, 800); qDebug()<<"begin test"<<endl; btn = new QPushButton(tr("open"),this); if (hasFocus()) { qDebug() << "has focus" << endl; } else { qDebug() << "NO focus" << endl; } } Widget::~Widget() { } void Widget::keyPressEvent(QKeyEvent *event) { qDebug()<<"try"<<endl; if(event->key() == Qt::Key_1) { qDebug()<<"press 1"<<endl; btn->move(50, 50); if (hasFocus()) { qDebug() << "Get focus" << endl; } else { qDebug() << "NO focus" << endl; } } }
But when I press the key,nothing happend. It seems that the application doesn't get the focus.
-
@xixi_cly the application gets the focus, I'm sure about it,
try either overriding the top most QWidget keypress event or - the probably better option - install an event filter on your application
-
I second the idea (from @J-Hilk ) to try installEventFilter.
Another (somewhat) common Qt debugging tactic is to use QT_LOGGING_RULES, but it isn't always clear to me which logging categories to enable.
In your case, doing this in the environment before app launch might produce useful logs:
export QT_LOGGING_RULES="qt.qpa.input* = true"