Qt窗口永久置顶

    xiaoxiao2023-03-24  3

    1、pro文件中调用Windows提供库:

    LIBS += -lUser32

    2、引用头文件

    #include "Windows.h"

    3、定义QTimer

    QTimer *m_timer;

    4、核心代码:

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

     

    转载请注明原文地址: https://ju.6miu.com/read-1200080.html
    最新回复(0)