Qt实现窗口阴影网上有多种实现方式,比如:
1.使用qt自带的方法,QGraphicsDropShadowEffect
2.通过在无边框背景透明的窗口中paintevent事件中绘制出来
3.通过dwmapi库的阴影功能具体代码如下:
#pragma once
#include <QWidget>
#include "ui_customwidgetframe.h"
class CustomWidgetFrame : public QWidget {
Q_OBJECT
public:
CustomWidgetFrame(QWidget * parent = Q_NULLPTR);
~CustomWidgetFrame();
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
private:
Ui::CustomWidgetFrame ui;
};
#include "customwidgetframe.h"
#include <dwmapi.h>
#include <windowsx.h>
#include <qt_windows.h>
#pragma comment(lib, "dwmapi.lib")
#pragma comment(lib, "user32.lib")
CustomWidgetFrame::CustomWidgetFrame(QWidget * parent) : QWidget(parent) {
ui.setupUi(this);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
bool visible = isVisible();
/*