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. QGraphicsDropShadowEffect and QResizeEvent
QtWS25 Last Chance

QGraphicsDropShadowEffect and QResizeEvent

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsdropshqresizeeventqlabelshadow
3 Posts 1 Posters 2.2k Views
  • 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.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 15 Feb 2017, 07:16 last edited by
    #1

    Hello,

    I'm using a custom QLabel class that is mainly used to display images/icons and emit Signals/do Stuff with mouseevents.

    My last additon was a shadow effect, using QGraphicsDropShadowEffect when the mouse hovers over the label.

    The problem is, when the effect is applied, it causes a resizeeffent for the whole programm and the min-width is more or less doubled.

    I could stop this with this->blockSignals(true); during the effect creations. But the labels are part of a QPropertyAnimation and as soon as the animation starts the resize is triggered again.

    Is there a way to prevent this? Is QGraphicsDropShadowEffect actually the correct why to archiv my goal - shadow of the label while mouse over - or should I do something else?
    Like, load a different pixmap that has a drawn shadow and swap between those two.

    {
    connect(this, &cLabel::hover, this, &cLabel::shadowEffect);
    }
    //Code excerpt where the effect is applied
    void cLabel::enableShadow(bool enable)
    {
        m_shadowEffect = enable;
        if(enable){
            this->blockSignals(true);
            effect = new QGraphicsDropShadowEffect(this);
            effect->setColor(QColor(110,152,226,255));
            effect->setBlurRadius(10);
            effect->setOffset(5);
            effect->setEnabled(false);
            this->setGraphicsEffect(effect);
            this->blockSignals(false);
        }else{
            effect->deleteLater();
        }
    }
    
    void cLabel::shadowEffect(bool status)
    {
        if(m_shadowEffect){
            if(status)
                effect->setEnabled(true);
            else
                effect->setEnabled(false);
        }
    }
    
    void cLabel::enterEvent(QEvent *event)
    {
        emit hover(true);
        event->ignore();
    }
    
    void cLabel::leaveEvent(QEvent *event)
    {
        emit hover(false);
        
        _Clicked = false;
        reset();
        
        event->ignore();
    }
    

    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 16 Feb 2017, 07:41 last edited by
      #2

      I've tried a couple of different things.

      all without success:

      • Applying and handling the DropShadowEffect from the parent widget
      • Disabling the effect before emitting the clicked Signal
      • Delays between signal and execution
      • Blocking all signals before the start of the QPropertyAnimation
      • setting a fixedSize for the MainWindow, user cant change the size, but upon the animations execution the MainWindow gets the new minSize anyway

      But I noticed, that it also happens when I change to a new side of my stackedwidget, but not when I click outside the application.

      I'm now down to a 2nd set of Pixmaps that have a predrawn shadow effect on them. Those I swap on mouse over.

      I'm not happy with it, but it works. If anyone has a better solution please tell me.

      Greetings.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 24 Feb 2017, 07:27 last edited by
        #3

        Ok,

        I'll mark this as solved.

        I wasn't able to do it with QGraphicsDropShadowEffect, and creating all images twice and including them in the rcs-file is simply a no go.

        Therefore I create a function, that draws a shadow - all 4 sides - around the the QImages, either at startup or during runtime.

        Here it is, in case anyone else needs something like it.

        QImage drawShadow(QImage img)
            {
                //Condition img allready has a transparent border 4 Pixel in this case
        
                //Create new Img with same Size
                QImage imgBGround(img.size(), img.format());
        
                //Fill it with transparency
                QPainter p(&imgBGround);
                QPen pen; pen.setStyle(Qt::NoPen);
                p.setPen(pen);
                p.setRenderHint(QPainter::Antialiasing);
                p.fillRect(QRect(0,0,img.width(), img.height()), QColor(255,255,255,0));
        
                //Draw Rounded Rectangle as Shadow
                QPainterPath path;
                path.addRoundedRect(QRect(0,0,img.width(), img.height()),15,15);
                p.fillPath(path,QColor(110,152,226));
                p.drawPath(path);
        
                //Draw Original Img over background
                p.drawImage(0,0,img);
        
                return imgBGround;
            }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1

        • Login

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