Qt隐藏任务栏项目

Qt隐藏任务栏项目

问题描述:

我有一个自定义的 QWidget,我只是不想让它显示在任务栏中.我有一个 QSystemTrayIcon 用于管理退出/最小化等.

I have a custom QWidget and I simple don't want it to show up in the taskbar. I have a QSystemTrayIcon for managing exiting/minimizing etc.

我认为您在这里唯一需要的是某种父占位符小部件.如果您在没有父级的情况下创建小部件,则将其视为*窗口.但是,如果您将其创建为*窗口的子窗口,则它被视为子窗口,并且本身不会获得任务栏条目.另一方面,父窗口也没有任务栏条目,因为您从未将其设置为可见:这里的代码对我有用:

I think the only thing you need here is some sort of parent placeholder widget. If you create your widget without a parent it is considered a top level window. But if you create it as a child of a top level window it is considered a child window und doesn't get a taskbar entry per se. The parent window, on the other hand, also doesn't get a taskbar entry because you never set it visible: This code here works for me:

class MyWindowWidget : public QWidget
{
public:
    MyWindowWidget(QWidget *parent)
        : QWidget(parent, Qt::Dialog)
    {

    }
};

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

    QMainWindow window;

    MyWindowWidget widget(&window);
    widget.show();

    return app.exec();
}

不会显示任何任务栏条目,如果这是您想要的.

No taskbar entry is ever shown, if this is want you intended.