Intercepting Tab key press to manage focus switching manually

前端 未结 4 1809
一向
一向 2020-12-16 22:58

I want to intercept Tab key press in my main window to prevent Qt from switching focus. Here\'s what I\'ve tried so far:



        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 23:25

    The most elegant way I found to avoid focus change is to reimplement in your class derived from QWidget the method bool focusNextPrevChild(bool next) and simply return FALSE. In case you want to allow it, return TRUE.

    Like other keys you get now also the key Qt::Key_Tab in keyPressEvent(QKeyEvent* event)

提交回复
热议问题