Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76141

QMainWindow::menuBar()->setFocus(Qt::MenuBarFocusReason) works wrong

    XMLWordPrintable

Details

    • All

    Description

      Hi

      I want show/hide QMainWindow::menuBar() and QMainWindow::statusBar() when user pres Alt key or Alt+ANY_KEY . Basic functionality I have done, but problem is with QMainWindow::menuBar() focus. I expect that QMainWindow::menuBar() automatically show focus indicator ALWAYS when it is show. I wrote this function:

       

      bool MainWindow::eventFilter(QObject* aObject, QEvent* aEvent)
      {
          QKeyEvent* lKeyEvent(dynamic_cast<QKeyEvent*>(aEvent));
          if(lKeyEvent && (lKeyEvent->type() == QEvent::KeyPress))
          {
              if(lKeyEvent->key() == Qt::Key_Alt)
              {
                  menuBar()->setHidden(!menuBar()->isHidden());
                  statusBar()->setHidden(!statusBar()->isHidden());
                  if(!menuBar()->isHidden())
                      menuBar()->setFocus(Qt::MenuBarFocusReason);    // Not works as expected
                  else
                      ui->plainTextEdit->setFocus();
                  return true;
              }
              else if(lKeyEvent->modifiers() & Qt::AltModifier)
              {
                  if(menuBar()->isHidden())
                  {
                      menuBar()->setHidden(false);
                      statusBar()->setHidden(false);
                  }
                  menuBar()->setFocus(Qt::MenuBarFocusReason);    // Not works as expected
              }
          }
      
          return QMainWindow::eventFilter(aObject, aEvent);
      }
      
      

      But if you run attached application and you simply hit few times alt - then you will see that focus is not set to QMainWindow::menuBar() for some unknown reason.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            szykcech Szyk Cech
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes