天天看点

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