简体   繁体   English

试图集中精力于QButtonGroup中的所有按钮

[英]Trying to get focus on all buttons in a QButtonGroup

I am trying to get focus on all the QPushButtons in QButtonGroup. 我试图把重点放在QButtonGroup中的所有QPushButtons上。 I am installing eventFilter on all buttons added in the button group and capturing the Tab key press event on each button and shifting the focus to next button. 我将在按钮组中添加的所有按钮上安装eventFilter,并捕获每个按钮上的Tab键按下事件,并将焦点移至下一个按钮。 I am able to achieve that, but the problem is while shifting the focus backwards using Shift + Tab. 我能够实现,但是问题是使用Shift + Tab将焦点向后移动时。 I am unable to capture the Shift + Tab event in the eventFilter. 我无法在eventFilter中捕获Shift + Tab事件。 Only shift modifier press works fine 只有换档键按下才能正常工作

Here is the code: 这是代码:

bool Widget::eventFilter( QObject * inObject, QEvent * inEvent )
{
    if( inEvent->type() == QEvent::KeyPress )
    {
      QKeyEvent * keyEvent = static_cast< QKeyEvent * >( inEvent );
      if( keyEvent )
      {
         if( keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers().testFlag( Qt::ShiftModifier ) )
         {
           //move focus backwards;
            return true;
         }
         return false;
      }
    }
}

Please Help ! 请帮忙 !

You should use Qt::Key_Backtab to achieve the shift+tab. 您应该使用Qt :: Key_Backtab来实现shift + tab。 No need to explicitly catch 2 modifiers. 无需显式捕获2个修饰符。 It is ready made in Qt 已准备好在Qt中制作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM