Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unexpected behaviour with QGraphicsOpacityEffect and custom widgets
Forum Updated to NodeBB v4.3 + New Features

Unexpected behaviour with QGraphicsOpacityEffect and custom widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 480 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheEnigmist
    wrote on last edited by
    #1

    I've a custom widget A with custom event filter function.
    On Enter/Leave event I trigger a QGraphicsOpacityEffect on other custom widget B to fades in/out it with a QPropertyAnimation.
    B has custom Enter/Leave event function that change an internal base widget (simply change a QPixmap).
    If I enter in A, B correctly fades-in , but as soon as I enter in B, it disappears (it calls Paint and paints a transparent widget).
    If I leave A then B comes back for duration of QPropertyAnimation.

    This behaviour doesn't appear when using QGraphicsBlurEffect
    Blur video
    Opacity video

    I really don't know why it does this with opacity, the function are the same...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      Can you provide a minimal compilable example reproducing this ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?
        Can you provide a minimal compilable example reproducing this ?

        T Offline
        T Offline
        TheEnigmist
        wrote on last edited by TheEnigmist
        #3

        @SGaist Hi, maybe I found a where the error is creating a minimal compilable example reproducing this.
        I'm using Qt6.3
        This is B
        B.h

        class B : public QWidget{
        	Q_OBJECT
        public:
        	B(const QPixmap& icon, QWidget* parent = nullptr);
        
        signals:
        	void clicked();
        
        protected:
        	bool eventFilter(QObject* obj, QEvent* event) override;
        
        private:
        	void updateIcon();
        	QLabel* labelIcon;
        	QPixmap icon;
        };
        

        B.cpp

        B::B(const QPixmap& icon, QWidget* parent): QWidget(parent){
            QHBoxLayout* base_layout = new QHBoxLayout;
            labelIcon = new QLabel;
            this->icon = icon;
            base_layout->addWidget(labelIcon);
            installEventFilter(this);
            setLayout(base_layout);
            updateIcon();
        }
        void B::updateIcon() {
            labelIcon->setPixmap(icon);
        }
        bool B::eventFilter(QObject* obj, QEvent* event) {
            if (event->type() == QEvent::MouseButtonRelease) emit clicked();
            //QEvent::Enter do something and than call update icon
            if (event->type() == QEvent::Enter) updateIcon();
            //QEvent::Leave do something and than call update icon
            if (event->type() == QEvent::Leave) updateIcon();
            return QObject::eventFilter(obj, event);
        }
        

        This is A
        A.h

        class A : public QWidget
        {
        	Q_OBJECT
        
        public:
        	A(QWidget *parent = nullptr);
        
        protected:
        	bool eventFilter(QObject* obj, QEvent* event) override;
        
        private:
        	QPropertyAnimation* fadeAnimation;
        };
        

        A.cpp

        A::A(QWidget* parent) : QWidget(parent){
        	//init layout
        	QVBoxLayout* mainLayout = new QVBoxLayout;
        	installEventFilter(this);
        	setLayout(mainLayout);
        	setCursor(Qt::PointingHandCursor);
        	installEventFilter(this);
        
        	//wrap widget to create nested graphic effect widget!
        	QWidget* wrap = new QWidget(this);
        	//CREATE B with a pixmap in it
        	B* b = new B(QPixmap("pixmap.png")); // pixmap.png is a simple colored rectangle
        	b->setParent(wrap);
        	b->move(10, 10);
        	b->setFixedSize(60, 40);
        	wrap->show();
        
        	QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect;
        	shadow->setOffset(0, 0);
        	shadow->setColor(QColor(60, 60, 60, 255));
        	shadow->setBlurRadius(5);
        
        	QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect;
        	opacityEffect->setOpacity(0);
        	
        	b->setGraphicsEffect(opacityEffect);
        	wrap->setGraphicsEffect(shadow);
        
        	fadeAnimation = new QPropertyAnimation(opacityEffect, "opacity");
        	fadeAnimation->setDuration(500);
        
        }
        
        bool A::eventFilter(QObject* obj, QEvent* event) {
        	if (event->type() == QEvent::Enter) {
        		fadeAnimation->setStartValue(0);
        		fadeAnimation->setEndValue(1);
        		fadeAnimation->setEasingCurve(QEasingCurve::InBack);
        		fadeAnimation->start();
        	}
        	if (event->type() == QEvent::Leave) {
        		fadeAnimation->setStartValue(1);
        		fadeAnimation->setEndValue(0);
        		fadeAnimation->setEasingCurve(QEasingCurve::InBack);
        		fadeAnimation->start();
        	}
        	return QObject::eventFilter(obj, event);
        }
        

        In main.cpp create A and then move your mouse over the image you loaded and you will see it will disappear.
        I found out that if I swap grapfic effect (b get shadow and wrap get opacity) I get a lot of warning when B disappear. This is the output:

        Warning QPainter::begin: A paint device can only be painted by one painter at a time.
        Warning QPainter::translate: Painter not active
        Warning QPainter::worldTransform: Painter not active
        Warning QWidgetEffectSourcePrivate::pixmap: Painter not active
        Warning QPainter::worldTransform: Painter not active
        Warning QPainter::setWorldTransform: Painter not active
        Warning QPainter::setWorldTransform: Painter not active
        

        So my try to nest two graphic effect failed totally, indeed if I remove shadow effect it does not trigger this behaviour.

        EDIT: I tried to remove second effect in my main code but there is still the behaviour, only with opacity. Maybe it overlaps Paint function and the error is triggered, but no warning in console this time

        1 Reply Last reply
        0
        • T Offline
          T Offline
          TheEnigmist
          wrote on last edited by TheEnigmist
          #4

          I made some step on this error.
          Based on this answer if I set nullptr on graphiceffect after propertyanimation the error disappear, but I lose the fade-out effect.

          Seems to be a bug since QGraphicEffect calls a paint event while the widget is painting the inner elements, triggering the warning and failing the paint at all

          EDIT: seems like qgrapficeffects is propagated on all inner element, or at least goes in conflict with inner elements

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Which version of Qt 6.3 are you using ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            T 1 Reply Last reply
            0
            • SGaistS SGaist

              Which version of Qt 6.3 are you using ?

              T Offline
              T Offline
              TheEnigmist
              wrote on last edited by
              #6

              @SGaist I'm using 6.3.0 with msvc compiler

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved