Saving space on small displays



  • Hi :-)

    I'm trying to save space on small displays. First thing I tried is to add a "fullscreen mode", triggered by a menu "F11" press like that:

    void MainWindow::viewFullScreen()
    {
        if (m_viewFullScreenAction->isChecked()) {
            setWindowFlags(Qt::FramelessWindowHint);
        } else {
            setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
        }
        show();
    }
    

    where m_viewFullScreenAction::triggered() is bound to MainWindow::viewFullScreen(). and I have set:

    m_viewFullScreenAction->setCheckable(true);
    m_viewFullScreenAction->setShortcut(QKeySequence(tr("F11")));
    

    Now, I try to do the same hiding the menu bar. But the problem is that I can hide the menu bar, but I can't re-show it again. I use the following function:

    void MainWindow::showMenuBar()
    {
        menuBar()->setVisible(m_showMenubarAction->isChecked());
    }
    

    It hides the menu bar on the first triggering, but it doesn't show it after pressing CTRL+M as soon as the menu is hidden.

    If I only do qDebug() << m_showMenubarAction->isChecked()in MainWindow::showMenuBar(), >I) get "true" and "false" alternatingly.

    So how does being invisible block triggering the QAction while being hidden?



  • @l3u_ said in Saving space on small displays:

    So how does being invisible block triggering the QAction while being hidden?

    Apparently it just does?... It was probably a design decision that actions don't apply to hidden windows, since they cannot have an active user context while hidden.

    Maybe attach your action to the menu bar's owning window instead of the bar itself.



  • The owner if the QAction does not change the behavior. As soon as the action is hidden, the shortcut is not accessible anymore.

    I worked around this using a global shortcut in addition:

    m_viewMenubarShortcut = new QShortcut(QKeySequence(tr("Ctrl+M")), this);
    m_viewMenubarShortcut->setContext(Qt::ApplicationShortcut);
    m_viewMenubarShortcut->setEnabled(false);
    connect(m_viewMenubarShortcut, &QShortcut::activated, m_showMenubarAction, &QAction::toggle);
    connect(m_viewMenubarShortcut, &QShortcut::activated, this, &MainWindow::showMenuBar);
    
    ...
    
    void MainWindow::showMenuBar()
    {
        menuBar()->setVisible(m_showMenubarAction->isChecked());
        m_viewMenubarShortcut->setEnabled(menuBar()->isHidden());
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.