桌面白板工具,需要悬浮工具
包含"windows.h"头文件
// 置顶
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
// 不置顶
::SetWindowPos(HWND(this->winId()), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
直接使用windows设置桌面置顶,透明窗口部分显示黑色,且拖动按钮绘制存在问题,如下图:
在构造函数中置顶
DesktopDrawWidget::DesktopDrawWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DesktopDrawWidget),
_transparent(true)
{
ui->setupUi(this);
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
connect(ui->pushButton_max, SIGNAL(signal_posChanged()), this, SLOT(slot_posChanged()));
slot_posChanged();
// QTimer::singleShot(3000, this, SLOT(slot_topMost()));
}
主要是先显示,然后再置顶
DesktopDrawWidget::DesktopDrawWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DesktopDrawWidget),
_transparent(true)
{
ui->setupUi(this);
// ::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
connect(ui->pushButton_max, SIGNAL(signal_posChanged()), this, SLOT(slot_posChanged()));
slot_posChanged();
QTimer::singleShot(0, this, SLOT(slot_topMost()));
}
void DesktopDrawWidget::slot_topMost()
{
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}