c++ - QSystemTrayIcon 并不总是出现

标签 c++ linux qt xfce

我编写了一个小程序来在合成器(xfwm4、dcompmgr、cairo-compmgr)之间切换,以帮助解决 nVidia 可能遇到的视频撕裂问题。它在系统托盘中创建一个具有其操作的图标。问题是当我运行我的程序时图标并不总是显示,并且在我切换到不同的合成器后它消失了。我已经在可以在这里看到的视频中捕获了它: https://www.youtube.com/watch?v=31qqOiaOdfw

我正在使用: 带有 Xfce 的 Manjaro Linux 64 位
QtCreator v.2.8.0 与 Qt 5.1

有人可以帮我解决这个问题吗?

compSwitcher.cpp

#include "compswitcher.h"
#include "ui_compswitcher.h"
#include <QMenu>
#include <QCloseEvent>
#include <QDebug>

compSwitcher::compSwitcher(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::compSwitcher)
{
    ui->setupUi(this);

    createActions();
    createIcon();
    setIcon();
    qDebug() << "Before trayIcon->show()\n";
    trayIcon->show();
    qDebug() << "After trayIcon->show()";

}

compSwitcher::~compSwitcher()
{
    delete ui;
    delete trayIcon;
    delete menu;
    delete xfwm4;
    delete close;
    delete dcompmgr;
}

void compSwitcher::createActions()
{
    close = new QAction(tr("&Quit"),this);
    QObject::connect(close, SIGNAL(triggered()), this, SLOT(endProgram()));

    xfwm4 = new QAction(tr("&xfwm4"), this);
    connect(xfwm4, SIGNAL(triggered()), this, SLOT(setXfwm4()));

    dcompmgr = new QAction(tr("&dcompmgr"), this);
    connect(dcompmgr, SIGNAL(triggered()), this, SLOT(setDcompmgr()));

    cairo = new QAction(tr("&cairo-compmgr"), this);
    connect(cairo,SIGNAL(triggered()), this, SLOT(setCairo()));
}

void compSwitcher::createIcon()
{
    menu = new QMenu(this);
    menu->addAction(xfwm4);
    menu->addAction(dcompmgr);
    menu->addAction(cairo);
    menu->addSeparator();
    menu->addAction(close);

    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(menu);

}

void compSwitcher::setIcon()
{
    QIcon ikona(":/new/prefix1/kuba_fan1.png");
    trayIcon->setIcon(QIcon(ikona));

}

void compSwitcher::setXfwm4()
{
    system("/home/dec/Programowanie/qt/compSwitcher/skrypty/xfwm4true.sh");
}

void compSwitcher::setDcompmgr()
{
    system("/home/dec/Programowanie/qt/compSwitcher/skrypty/dcompmgr.sh");
}

void compSwitcher::setCairo()
{
    system("/home/dec/Programowanie/qt/compSwitcher/skrypty/cairo.sh");

}

最佳答案

我遇到了类似的问题,在我的情况下,托盘从未显示。

我还有:带有 Xfce 的 Manjaro Linux 64bit

我通过将面板更改为 tint2 解决了这个问题。我认为这是 xfce-panel 的问题。

关于c++ - QSystemTrayIcon 并不总是出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18287410/

相关文章:

linux - 为什么导入的函数在 Linux 中被间接调用?

qt - CMake 中 QMake 的 CONFIG+=console

c++ - 引发 QT QEvent::WindowActivate 事件

c++ - ISO C++ 禁止声明没有类型的 'vector'

c++ - BrainBench 就业测试

linux - 这个sed有什么问题?

linux - 如何为任何版本的 Linux/Ubuntu 制作与 CQtDeployer 兼容的应用程序?

python - 你如何在 Qt 中制作链接 slider ?

c++ - 派生类成员函数在 C++ 中失败

c++ - 对两个对应的数组进行排序