Qt笔记-窗口程序在任务栏中隐藏及永久置顶

这里主要是因为想搞个水印的程序。

感觉视频加水印比较麻烦,不如自己写个加水印的程序。

如下的效果:

这里有两点要注意,一个是在任务栏中隐藏:

主要是

Qt::Tool

    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Window | Qt::FramelessWindowHint | Qt::Tool);
    setAttribute(Qt::WA_TranslucentBackground);

关于置顶,Qt提供了

Qt::WindowStaysOnTopHint通过这个枚举去做,但是如果有其他程序也置顶了,自己的程序就会被压着,所以要让其实时刷新到最顶端。

这里介绍个函数

通过实时调用这个函数使其置顶

Qt相关代码如下:

pro文件:

LIBS += -lUser32

相关调用

void Widget::scrollActive()
{
    QString temp_string = m_string + "当前时间:" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    if(nPos > temp_string.length()){

        nPos=0;
    }

    ui->label->setText(temp_string.mid(nPos));
    nPos++;

    //置顶
#ifdef Q_OS_WIN32
    SetWindowPos((HWND)this->winId(), HWND_TOPMOST, this->pos().x(), this->pos().y(), this->width(), this->height(), SWP_SHOWWINDOW);
#endif
}

最后一个参数:

发布了1331 篇原创文章 · 获赞 7073 · 访问量 256万+

猜你喜欢

转载自blog.csdn.net/qq78442761/article/details/105374050