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 on form widget
Qt 6.11 is out! See what's new in the release blog

QGraphicsDropShadowEffect on form widget

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 11.9k 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.
  • J Offline
    J Offline
    janfaroe
    wrote on last edited by
    #1

    Greetings all. I'm having trouble showing a drop shadow on my form widgets. A quick test with a QLabel poses no problem; the shadow shows fine.

    I should mention that the widgets are laid out with my own layout manager - also that I am applying the shadow as I am adding the widgets to the layout. I tried applying shadow before and after adding to layout; no difference.

    Is there anything I should be beware of in order to make this work? Or does shadows only work with "simple" widgets?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      janfaroe
      wrote on last edited by
      #2

      Ok, it works if adding the shadow in the form widget constructor:

      ui->setupUi(this);
      QGraphicsDropShadowEffect* dropShadowEffect = new QGraphicsDropShadowEffect(this);
      this->setGraphicsEffect(dropShadowEffect);

      But, now all sub widgets inherits the effect. Calling QWidget::setGraphicsEffect(NULL) for subitems does not change anything.

      Suggestions?

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

        Hi,

        Did you try:

        @dropShadowEffect->setEnabled(false);@

        ?

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          janfaroe
          wrote on last edited by
          #4

          Um, I'm not sure how that would work. I'm having one instance of the effect, which is applied only on the top level widget. Disabling it would sort of defeat the purpose.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can explicitly set a background color on the top level widget. This will force the drop shadow effect to treat it as a opaque rectangle (or whatever the shape is) and apply the effect around it leaving children unchanged.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              janfaroe
              wrote on last edited by
              #6

              I suppose you mean with a stylesheet? Just did this on the top level widget; did not stop the effect from propagating to the children:

              #MediaItemForm {
              background-color:#FFFFFF;
              }

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

                Sorry, I misread your post.

                From the documentation of QWidget::setGraphicsEffect:

                bq. Note: This function will apply the effect on itself and all its children.

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

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  janfaroe
                  wrote on last edited by
                  #8

                  SGaist: Yes, but how to avoid it? It would be a terrible solution to subclass all child elements to ignore the effect.

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hm, that's weird. This is what I'm getting with and without the background:
                    !http://img46.imageshack.us/img46/9097/ifgk.jpg(drop shadow example)!

                    1 Reply Last reply
                    0
                    • raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #10

                      [quote author="janfaroe" date="1383368356"]SGaist: Yes, but how to avoid it? It would be a terrible solution to subclass all child elements to ignore the effect.[/quote]

                      you can try a method which sets the effect for you (untested):
                      @
                      setDropShadowEffectOnWidgetOnly(QWidget* w)
                      {
                      if( ! w ) return;

                      w->setGraphicsEffect( new QGraphicsDropShadowEffect );
                      foreach( QWidget* child, this->findChildren<QWidget*>() )
                           child->setGraphicsEffect(0);   //unset effect for children
                      

                      }
                      @

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        janfaroe
                        wrote on last edited by
                        #11

                        Chris Kawa: That's odd indeed. And you set bg color with style sheet? Could it be one of these things that despite all are platform dependent? Or because I'm using 5.2 beta?

                        [quote author="Chris Kawa" date="1383555753"]Hm, that's weird. This is what I'm getting with and without the background:
                        !http://img46.imageshack.us/img46/9097/ifgk.jpg(drop shadow example)![/quote]

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          janfaroe
                          wrote on last edited by
                          #12

                          Thanks for the suggestion. However, since I'm rendering quite a few parent widgets, it does not seem terribly efficient? But of course, if anything else fails, I might resort to it.

                          [quote author="raven-worx" date="1383557940"][quote author="janfaroe" date="1383368356"]SGaist: Yes, but how to avoid it? It would be a terrible solution to subclass all child elements to ignore the effect.[/quote]

                          you can try a method which sets the effect for you (untested):
                          @
                          setDropShadowEffectOnWidgetOnly(QWidget* w)
                          {
                          if( ! w ) return;

                          w->setGraphicsEffect( new QGraphicsDropShadowEffect );
                          foreach( QWidget* child, this->findChildren<QWidget*>() )
                               child->setGraphicsEffect(0);   //unset effect for children
                          

                          }
                          @[/quote]

                          1 Reply Last reply
                          0
                          • raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by
                            #13

                            [quote author="janfaroe" date="1383558917"]Thanks for the suggestion. However, since I'm rendering quite a few parent widgets, it does not seem terribly efficient?
                            [/quote]
                            yes most probably.

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            1 Reply Last reply
                            0
                            • Chris KawaC Offline
                              Chris KawaC Offline
                              Chris Kawa
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              [quote author="janfaroe" date="1383558759"]Chris Kawa: That's odd indeed. And you set bg color with style sheet? Could it be one of these things that despite all are platform dependent? Or because I'm using 5.2 beta?
                              [/quote]

                              I'm using Qt5.1.1 with both VS2012 and MinGW. This is basically all the code I wrote:
                              @
                              ui->frame->setStyleSheet("QFrame { background-color: palette(window)}");
                              ui->frame->setGraphicsEffect(new QGraphicsDropShadowEffect(this));
                              ui->frame_2->setGraphicsEffect(new QGraphicsDropShadowEffect(this));
                              @

                              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