2015-04-22 163 views
2

我想從任務欄隱藏我的QT應用程序?我在Google找不到任何東西,所以我在這裏問。 從Qt隱藏任務欄項目(Qt Hide Taskbar Item)和解決方案this-> hide()沒有幫助。如何在任務欄上隱藏應用程序?

的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; 
    } 

編輯: 有了這樣的窗口代碼爲空。

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(); 
} 

通過使用Qt :: Tool標誌求解。

+0

可能重複的[Qt Hide Taskbar Item](http://stackoverflow.com/questions/4055506/qt-hide-taskbar-item) – NathanOliver

+0

但是從http: //stackoverflow.com/questions/4055506/qt-hide-taskbar-item沒有幫助。 – Piesek64

+0

什麼部分沒有幫助? – NathanOliver

回答

-1

Qt :: Tool標誌對我來說有其他問題,比如當它的狀態變爲非活動狀態時,這個小部件/窗口將被隱藏。 我會建議你使用Qt :: ToolTip

相關問題