[Qt-interest] SystemTrayIcon & ContextMenu Problems on MAC OSX 10.5.8

Raja Rokkam rokkamraja at gmail.com
Fri Jul 30 09:58:33 CEST 2010


Hi,

  I have a very simple code which works well on windows but doesnt work on
OSX 10.5.8.

TrayIcon when clicked shows up a "ContextMenu" with one entry.

This "ContextMenu" has another submenu with a few entries.

*PROBLEM 1: *When I click on a particular entry in the submenu, I need the
entire submenu to be disabled. However, it doesnt happen.

*PROBLEM 2:  *After disabling the submenu, when I click on the first level
entry, I need to re-enable the submenu.

The code below works fine on Windows but not on MAC.

My main.cpp file:
#include <QtGui>

#include <QSystemTrayIcon>
#include <QMenu>

class MyWidget : public QMenu
{
    Q_OBJECT

public:
    MyWidget ()
    {
        QMenu *menu = new QMenu();

        shareAction = this->addAction( "Share" );
        shareAction->setMenu( menu );
        desktopAction = new QAction("Desktop", this);
        regionAction = new QAction("Region", this);
        applicationAction = new QAction("Application", this);

        //connect(shareAction, SIGNAL(triggered()), this,
SLOT(disableActions()));
        connect(desktopAction, SIGNAL(triggered()), this,
SLOT(disableActions()));
        connect(regionAction, SIGNAL(triggered()), this,
SLOT(disableActions()));
        connect(applicationAction, SIGNAL(triggered()), this,
SLOT(disableActions()));

        menu->addAction(desktopAction);
        menu->addAction(regionAction);
        menu->addAction(applicationAction);
    }

public slots:
    void disableActions()
    {
        desktopAction->setEnabled(false);
        regionAction->setEnabled(false);
        applicationAction->setEnabled(false);
    }

private:
    QAction *shareAction, *desktopAction, *regionAction, *applicationAction;
};

#include "main.moc"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    MyWidget *trayMenu = new MyWidget();

    QSystemTrayIcon *trayIcon = new QSystemTrayIcon();
    trayIcon->setContextMenu( trayMenu );
    trayIcon->setVisible( true );


    return app.exec();
}

My test.pro file

TEMPLATE = app
TARGET = test
DESTDIR = .
QT += core gui
CONFIG += release
SOURCES += main.cpp


Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100730/daa860d6/attachment.html 


More information about the Qt-interest-old mailing list