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. Apply QGraphicsBlurEffect to a window
Forum Updated to NodeBB v4.3 + New Features

Apply QGraphicsBlurEffect to a window

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 7.8k 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.
  • E Offline
    E Offline
    evergreen
    wrote on last edited by
    #1

    Hello,

    In my application, my final goal is to blur background the current window when a modal QDialog pops up.
    To start, I want to apply it to the current mainwindow but I don't really understand how QGraphicsBlurEffect really works.
    Can someone explain to my how to use it to blur a window. I try to pass the window as argument but it's not working.

    Thanks a lot.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      Does the following example help?

      @#include <QtGui>

      class Demo : public QWidget {
      Q_OBJECT
      public:
      Demo(){
      setLayout(new QVBoxLayout);
      QPushButton *pb = new QPushButton("Toggle Blur");
      layout()->addWidget(pb);
      pb->setCheckable(true);
      connect (pb, SIGNAL(clicked(bool)), SLOT(testSlot(bool)));
      }

      private slots:
      void testSlot(bool blurred){
      QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this) ;
      setGraphicsEffect(blurred? effect : 0);
      }
      };

      #include "main.moc"

      int main( int argc, char** argv ){
      QApplication app( argc, argv );
      Demo w;
      w.show();
      return app.exec();
      }

      @

      1 Reply Last reply
      0
      • E Offline
        E Offline
        evergreen
        wrote on last edited by
        #3

        Yes Sigrid, It helped a lot, I didn't realized it was that simple.
        However, my final goal to apply it on a QGraphicView but according to what I find on tn the doc it does not seems to be possible. Am I right?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sigrid
          wrote on last edited by
          #4

          Which part of the documentation are you referring to? Does setting the effect on the view's viewport() or on the item itself work for you?

          @#include <QtGui>

          class Demo : public QWidget {
          Q_OBJECT
          public:
          Demo(){
          setLayout(new QVBoxLayout);
          QPushButton *pb = new QPushButton("Toggle Blur");
          layout()->addWidget(pb);
          pb->setCheckable(true);

          view = new QGraphicsView(this);
          scene = new QGraphicsScene(view);
          view->setScene(scene);
          item1 = new QGraphicsEllipseItem();
          QRect rectangle(10, 20, 80, 60);
          item1->setRect(rectangle);
          scene->addItem(item1);

          layout()->addWidget(view);
          connect (pb, SIGNAL(clicked(bool)), SLOT(testSlot(bool)));
          }

          private slots:
          void testSlot(bool blurred){
          QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this) ;
          setGraphicsEffect(blurred? effect : 0);

          QGraphicsBlurEffect *effect2 = new QGraphicsBlurEffect(view) ;
          view->viewport()->setGraphicsEffect(blurred? effect2 : 0);
          }
          private:
          QGraphicsView *view;
          QGraphicsScene *scene;
          QGraphicsEllipseItem *item1;
          };

          #include "main.moc"

          int main( int argc, char** argv ){
          QApplication app( argc, argv );
          Demo w;
          w.show();
          return app.exec();
          }

          @

          1 Reply Last reply
          0
          • E Offline
            E Offline
            evergreen
            wrote on last edited by
            #5

            ouch
            I wasn't applying the effect to the viewport port directly to the QGraphicsView
            I shall test your way soon thanks

            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