Qt World Summit: Register Today!

QMainWindow: Minimize to dash board on Ubuntu 18.04

  • I want to minimize a QMainWindow to an icon on the dash board on the left side of the screen on Ubuntu 18.04.

    When the "show()" function is called and the QMainWindow is visible I see the icon for my application on the left side dash.

    However, when the "hide()" function is called on QMainWindow the application is no longer visible which is fine but the dashboard icon also disappears. I want to minimize so that the application is no longer visible but there is still a dash board icon.

  • @anshah
    For minimization and icon, you need to use QMainWindow::showMinimized(), not QMainWindow::hide().

  • @JonB
    I am now able to see the icon when minimizing.

    So there is still one small problem. My application has been using a QSystemTrayIcon to show/hide the main window. When the Main Window is visible I have it minimizing to an icon now. The problem is in order to have the Main Window display again I need to click on the Dash Board minimized icon now. The QSystemTrayIcon is not responsive when the Main Window is in minimized state. I would like the Main Window to come up with either Dash Board icon or QSystemTrayIcon.

    Here's my code:

    connect(m_pTrayIcon,   SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this,          SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
    // Slot to handle tray icon activated signal
    void MyMainWindow::onActivated(QSystemTrayIcon::ActivationReason r)
        if (r == QSystemTrayIcon::Trigger)
            if (!this->isVisible() || this->isMinimized())

Log in to reply