#include "maskLayer.h" #include #include MaskLayer::MaskLayer(QWidget *parent) : QWidget(parent) { setObjectName("maskLayer"); setFocusPolicy(Qt::NoFocus); setAttribute(Qt::WA_TranslucentBackground); // 启用透明背景 setStyleSheet("background:rgba(112,128,144,180);"); hide(); } MaskLayer::~MaskLayer() {} //重写paintEvent触发背景绘制,否则实例化对象不显示 void MaskLayer::paintEvent(QPaintEvent *event) { QStyleOption opt; opt.initFrom(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); QWidget::paintEvent(event); }