修复遮罩层的一些问题

qt6
zcy 2021-05-06 19:46:28 +08:00
parent df324da102
commit 231407dff1
1 changed files with 7 additions and 4 deletions

11
Qss.cpp
View File

@ -1662,7 +1662,7 @@ QssMaskWidget::QssMaskWidget(QWidget *parent)
parent->installEventFilter(this); parent->installEventFilter(this);
mParent = parent; mParent = parent;
} }
this->installEventFilter(this);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);// 无边框 无任务栏 setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Tool);// 无边框 无任务栏
setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明
@ -1677,21 +1677,24 @@ QssMaskWidget::~QssMaskWidget()
bool QssMaskWidget::eventFilter(QObject *obj, QEvent *ev) bool QssMaskWidget::eventFilter(QObject *obj, QEvent *ev)
{ {
if(obj != this){ if(obj != this){
qDebug()<<obj->objectName()<<ev;
if(mParent != nullptr){ if(mParent != nullptr){
if(mParent->parentWidget() != nullptr){ if(mParent->parentWidget() != nullptr){
qDebug()<<mParent->parentWidget()->geometry();
this->move(mParent->parentWidget()->geometry().x(),mParent->parentWidget()->geometry().y()); this->move(mParent->parentWidget()->geometry().x(),mParent->parentWidget()->geometry().y());
this->show();
this->raise();
} }
} }
} }
if(obj == this){
return true;
}
return false; return false;
} }
void QssMaskWidget::paintEvent(QPaintEvent *event) void QssMaskWidget::paintEvent(QPaintEvent *event)
{ {
QPainter paint(this); QPainter paint(this);
paint.begin(this);
auto kBackgroundColor = QColor(1, 1, 1); auto kBackgroundColor = QColor(1, 1, 1);
kBackgroundColor.setAlpha(0.1 * 255);// 透明度为0 kBackgroundColor.setAlpha(0.1 * 255);// 透明度为0
paint.setRenderHint(QPainter::Antialiasing, true); paint.setRenderHint(QPainter::Antialiasing, true);