From 62108fd5b7928fc1ae1f55e27a227d68a55a9f6a Mon Sep 17 00:00:00 2001 From: johanneshilden Date: Thu, 12 Oct 2017 22:10:43 +0300 Subject: [PATCH] Fix Drawer peculiarities --- components/qtmaterialdrawer.cpp | 41 ++++++++++++++++++++++----------- components/qtmaterialdrawer.h | 1 + 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/components/qtmaterialdrawer.cpp b/components/qtmaterialdrawer.cpp index ed4db12..8f44093 100644 --- a/components/qtmaterialdrawer.cpp +++ b/components/qtmaterialdrawer.cpp @@ -54,9 +54,6 @@ void QtMaterialDrawerPrivate::init() widget->setParent(q); - q->setAttribute(Qt::WA_TransparentForMouseEvents); - q->setAttribute(Qt::WA_NoSystemBackground); - stateMachine->start(); QCoreApplication::processEvents(); } @@ -157,10 +154,8 @@ void QtMaterialDrawer::openDrawer() if (d->autoRaise) { raise(); } - if (d->overlay) { - setAttribute(Qt::WA_TransparentForMouseEvents, false); - setAttribute(Qt::WA_NoSystemBackground, false); - } + setAttribute(Qt::WA_TransparentForMouseEvents, false); + setAttribute(Qt::WA_NoSystemBackground, false); } void QtMaterialDrawer::closeDrawer() @@ -169,8 +164,28 @@ void QtMaterialDrawer::closeDrawer() emit d->stateMachine->signalClose(); - setAttribute(Qt::WA_TransparentForMouseEvents); - setAttribute(Qt::WA_NoSystemBackground); + if (d->overlay) { + setAttribute(Qt::WA_TransparentForMouseEvents); + setAttribute(Qt::WA_NoSystemBackground); + } +} + +bool QtMaterialDrawer::event(QEvent *event) +{ + Q_D(QtMaterialDrawer); + + switch (event->type()) + { + case QEvent::Move: + case QEvent::Resize: + if (!d->overlay) { + setMask(QRegion(d->widget->rect())); + } + break; + default: + break; + } + return QtMaterialOverlayWidget::event(event); } bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event) @@ -191,10 +206,11 @@ bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event) } case QEvent::Move: case QEvent::Resize: { - QLayout *lout = d->widget->layout(); - if (lout && 16 != lout->contentsMargins().right()) { - lout->setContentsMargins(0, 0, 16, 0); + QLayout *lw = d->widget->layout(); + if (lw && 16 != lw->contentsMargins().right()) { + lw->setContentsMargins(0, 0, 16, 0); } + break; } default: break; @@ -211,7 +227,6 @@ void QtMaterialDrawer::paintEvent(QPaintEvent *event) if (!d->overlay || d->stateMachine->isInClosedState()) { return; } - QPainter painter(this); painter.setOpacity(d->stateMachine->opacity()); painter.fillRect(rect(), Qt::SolidPattern); diff --git a/components/qtmaterialdrawer.h b/components/qtmaterialdrawer.h index 2ba313c..7bf3219 100644 --- a/components/qtmaterialdrawer.h +++ b/components/qtmaterialdrawer.h @@ -34,6 +34,7 @@ public slots: void closeDrawer(); protected: + bool event(QEvent *event) Q_DECL_OVERRIDE; bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;