添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
飘逸的橙子  ·  uart rx buffer length ...·  1 月前    · 
卖萌的枇杷  ·  Send Email with Java ...·  1 月前    · 
腼腆的香菇  ·  Events | Microsoft ...·  2 月前    · 
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

在按键机上使用qt测试按键,窗口无法获取焦点,按键不生效,是不是我的代码写的不对?

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() << "has focus" << endl;
        } else {
            qDebug() << "NO focus" << endl;