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. How to make a QGraphicsEffect show?

How to make a QGraphicsEffect show?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.0k 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.
  • M Offline
    M Offline
    Mustapha Mond
    wrote on last edited by
    #1

    Hello Forum,

    I try to blur a GraphicsView while doing some heavy lifting, but it doesn't get displayed until it's too late (upon reentering the event loop).

    [Code]
    QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this);
    ui->myGraphicsView->viewport()->setGraphicsEffect(effect);
    doSomeLongishCalculation();
    ui->myGraphicsView->viewport()->setGraphicsEffect(0);
    [/Code]

    Inserting a 'qApp->processEvents()' doesn't help.

    What am I doing wrong? Thank you for any clues.

    Mustapha

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      QGraphicsItem::setGraphicsEffect

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PeterSvP
        wrote on last edited by
        #3

        It depends where you are applying the effect.

        On widgets and QGraphicsItems it's straight-forward - just setGraphicsEffect.

        On QImage/QPixmap/QIcon, it's complicated, but possible. You MUST use QImage for actual rendering, that is why my function is QImage-centric.

        @QImage applyEffectToImage(QImage src, QGraphicsEffect effect, int extent)
        {
        if(src.isNull()) return QImage(); //No need to do anything else!
        if(!effect) return src; //No need to do anything else!
        QGraphicsScene scene;
        QGraphicsPixmapItem item;
        item.setPixmap(QPixmap::fromImage(src));
        item.setGraphicsEffect(effect);
        scene.addItem(&item);
        QImage res(src.size()+QSize(extent
        2, extent2), QImage::Format_ARGB32);
        res.fill(Qt::transparent);
        QPainter ptr(&res);
        scene.render(&ptr, QRectF(), QRectF( -extent, -extent, src.width()+extent
        2, src.height()+extent*2 ) );
        return res;
        }
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PeterSvP
          wrote on last edited by
          #4

          It depends where you are applying the effect.

          On widgets and QGraphicsItems it's straight-forward - just setGraphicsEffect.

          On QImage/QPixmap/QIcon, it's complicated, but possible. You MUST use QImage for actual rendering, that is why my function is QImage-centric.

          @QImage applyEffectToImage(QImage src, QGraphicsEffect effect, int extent)
          {
          if(src.isNull()) return QImage(); //No need to do anything else!
          if(!effect) return src; //No need to do anything else!
          QGraphicsScene scene;
          QGraphicsPixmapItem item;
          item.setPixmap(QPixmap::fromImage(src));
          item.setGraphicsEffect(effect);
          scene.addItem(&item);
          QImage res(src.size()+QSize(extent
          2, extent2), QImage::Format_ARGB32);
          res.fill(Qt::transparent);
          QPainter ptr(&res);
          scene.render(&ptr, QRectF(), QRectF( -extent, -extent, src.width()+extent
          2, src.height()+extent*2 ) );
          return res;
          }
          @

          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