简体   繁体   中英

How to hide application on taskbar?

I am trying to hide my QT application from taskbar? I cannot find anything in Google so I asking here. Solution from Qt Hide Taskbar Item ( Qt Hide Taskbar Item ) and this->hide() is not helping.

main.cpp

#include "status_bar.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    status_bar w;
    w.show();

    return a.exec();
}

status_bar.cpp:

    #include "status_bar.h"
    #include "ui_status_bar.h"
    #include <stdlib.h>
    #include <QTime>
    #include <QTimer>
    #include <QApplication>
    #include <QDesktopWidget>

    status_bar::status_bar(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::status_bar)
    {
        ui->setupUi(this);
        setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
        resize(QApplication::desktop()->width(),36);
        ui->time->move(QApplication::desktop()->width()-ui->time->size().width(),10);
        ui->username->setText(getenv("USER"));
        timeupdate = new QTimer(this);
        connect(timeupdate, SIGNAL(timeout()),
                  this, SLOT(UpdateClock()));
        timeupdate->start(100);
    }

    void status_bar::UpdateClock()
    {
        ui->time->setText(QTime::currentTime().toString("HH:mm"));
    }

    status_bar::~status_bar()
    {
        delete ui;
    }

EDIT: With code like this window is empty.

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

    }
};

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

    status_bar window;

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

    return app.exec();
}

Solved by using Qt::Tool flag.

Qt::Tool flag has other problems for me, like this widget/windows is hidden when its state becomes inactive. I would recommend you to use Qt::ToolTip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM