QWidgetAction in systemtray works in centos but unable to display in ubuntu



  • Qt version: 5.6.1
    OS version:

    1. centos 6.3
    2. ubuntu 14.04

    here is the code which run normal in centos but fails in ubuntu.

    In ubuntu , the test action shows normally however the custom widget turn out to be a blank action.

    why this happened?

    #include <QApplication>
    #include <QDialog>
    #include <QBoxLayout>
    #include <QToolBar>
    #include <QStyle>
    #include <QWidgetAction>
    #include <QSpinBox>
    #include <QMenu>
    
    #include <QSystemTrayIcon>
    
    class MyWidgetAction : public QWidgetAction
    {
    public:
        MyWidgetAction(QObject *parent) : QWidgetAction(parent) {}
        virtual ~MyWidgetAction() {}
    protected:
        virtual QWidget *createWidget(QWidget *parent) {
            QSpinBox *sb = new QSpinBox(parent);
            sb->setToolTip("Spin");
            return sb;
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QMenu menu;
        menu.addAction(QString("test"));
        QWidgetAction *wa = new MyWidgetAction(&menu);
        menu.addAction(wa);
        tray.setContextMenu(&menu);
        tray.show();
        return a.exec();
    }
    
    

  • Moderators

    Hi! What desktop environment are you using on Ubuntu? Unity?



  • the desktop environment is unity


Log in to reply
 

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