【问题标题】:Qt tab order keysQt 制表符顺序键
【发布时间】:2014-03-07 19:41:06
【问题描述】:

用户可以通过“Tab”键或箭头键“”来逐步浏览 QtGUI 的小部件。

有人知道如何为此禁用箭头键吗?我需要箭头键来做其他事情。

【问题讨论】:

    标签: c++ qt qwidget qtgui qevent


    【解决方案1】:

    您需要在自己的 QWidget 子类中重新实现 corresponding event,如下所示:

    bool MyWidget::keyPressEvent(QKeyEvent *keyEvent)
    {
        if (keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) {
            // Do nothing
        } else {
            QWidget::keyPressEvent(keyEvent);
        }
    }
    

    【讨论】:

      【解决方案2】:

      只需重新实现主窗口的 event() 或 keyPressEvent() / keyReleaseEvent()。在重新实现的方法中,您可以放置​​所需的操作。

      【讨论】:

        【解决方案3】:

        我可能会为此目的使用 QAction。所以你不需要子类化。

        QTabBar *tabBar;
        ........................
        QAction* pLeftArrowAction = new QAction(this);
        pLeftArrowAction->setShortcut(Qt::Key_Left);
        QAction* pRightArrowAction = new QAction(this);
        pRightArrowAction->setShortcut(Qt::Key_Right);
        tabBar->addActions(QList<QAction*>() << pLeftArrowAction << pRightArrowAction);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-02-08
          • 1970-01-01
          • 2017-02-26
          • 1970-01-01
          • 2013-01-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多