Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding widget to QSystemTrayIcon
Qt 6.11 is out! See what's new in the release blog

Adding widget to QSystemTrayIcon

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 524 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • denix56D Offline
    denix56D Offline
    denix56
    wrote on last edited by denix56
    #1

    I need something like small widget, hanging constantly near system tray. I decided to add QWidgetAction to menu and setContextMenu() for QSystemTrayIcon. But it does not work, widget does not appear. If i add that action to QMenubar, everything ok.

    QWidget *TrayWidgetAction::createWidget(QWidget *parent)
    {
        auto trayWidget = new QWidget(parent);
        inputLangs = new QComboBox(trayWidget);
        outputLangs = new QComboBox(trayWidget);
        QStandardItemModel* model = new QStandardItemModel(inputLangs);
        proxy1 = new QSortFilterProxyModel();
        proxy1->setSourceModel(model);
        proxy1->sort(0);
        inputLangs->setModel(proxy1);
    
        auto input = new TrayInpuTextEdit(trayWidget);
        auto output = new QTextEdit(trayWidget);
        auto grid = new QGridLayout(trayWidget);
    
        input->setFixedSize(110,70);
        output->setFixedSize(110,70);
    
        grid->addWidget(input,0,0,1,1,Qt::AlignCenter);
        grid->addWidget(output,0,1,1,1,Qt::AlignCenter);
        grid->addWidget(inputLangs,1,0,1,1);
        grid->addWidget(outputLangs,1,1,1,1);
        grid->setContentsMargins(1,1,1,1);
    
        trayWidget->setFixedSize(225,100);
        trayWidget->setLayout(grid);
        return trayWidget;
    }
    

    and the creating:

        widgetAction = new TrayWidgetAction(this);
        auto trayMenu = new QMenu(this);
        trayMenu->addAction(widgetAction);
        trayIcon->setContextMenu(trayMenu);
        trayIcon->show();
    

    Also i have found this bugreport:
    https://bugreports.qt.io/browse/QTBUG-26840

    UPDATE:
    On Windows it is working, so the problem is only on Linux

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved