[Qt-interest] How to hide an "easter egg" QMenu ?

Ed Sutton ESutton at fescorp.com
Wed Jun 9 19:13:01 CEST 2010


Hi Christopher,

Hello Edd,

I think you're trying to hide the object menuTest which is the pop-up dialog that appears when you click on the associated menuAction in the menu bar. You in fact want to hide or show the associated menu action and this is something different. To do this, I would do something like this:

void MainWindow::on_easter_egg_activate()
{
    static bool easterEggActivated= false;

    if (!easterEggActivated)
    {
        ui->menuBar->removeAction(ui->menuTest->menuAction());
        easterEggActivated true;

    }
    else
    {
        ui->menuBar->addAction(ui->menuTest->menuAction());
        easterEggActivated= false;
    }

}

Thank you! I confirm it works on Mac and Red Hat Enterprise Linux 5.2.  I created the menu normally in Qt Creator UI designer then conditionally removed or added the menu action from the menuBar as your example above clearly demonstrated.

Thank you very much for your patience and taking the time to create a sample application!

-Ed





More information about the Qt-interest-old mailing list