2

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.

Community
  • 1
  • 1
Piesek64
  • 67
  • 1
  • 8
  • possible duplicate of [Qt Hide Taskbar Item](http://stackoverflow.com/questions/4055506/qt-hide-taskbar-item) – NathanOliver Apr 22 '15 at 16:19
  • But solution from http://stackoverflow.com/questions/4055506/qt-hide-taskbar-item is not helping. – Piesek64 Apr 22 '15 at 16:22
  • what part of it is not helping? – NathanOliver Apr 22 '15 at 16:24
  • `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(); }` modified to work with my class name. – Piesek64 Apr 22 '15 at 16:25
  • You aren't following the code/instructions from the answer. You need to make `QMainWindow` in main and pass it to the status bar constructor to make status bar a child window. – NathanOliver Apr 22 '15 at 16:34
  • 1
    Also, with solution from stackoverflow.com/questions/4055506/qt-hide-taskbar-item there is no any widgets. Only background. – Piesek64 Apr 22 '15 at 16:38

1 Answers1

-1

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