天天看點

Qt視窗永久置頂

1、pro檔案中調用Windows提供庫:

LIBS += -lUser32      

2、引用頭檔案

#include "Windows.h"      
QTimer *m_timer;      
m_timer = new QTimer();
m_timer->start(1000); //程式每隔1秒置頂一次
 
connect(m_timer, &QTimer::timeout, [=]{
#ifdef Q_OS_WIN32
    SetWindowPos((HWND)this->winId(),HWND_TOPMOST,this->pos().x(),this->pos().y(),this->width(),this->height(),SWP_SHOWWINDOW);
#endif //要在windows上不擷取焦點切置頂,必須用Windows API
});