Paint shadow inside an QImage or QGraphicsEffect Shadow... html page doc



  • How can i make a shadow allround one page 4-6 pixel?
    QGraphicsEffect is only for widged..?

    /// Background image for 1 html page in subclass QAbstractScrollArea A4 or other
    static QImage onepageimage( const QRectF big , qreal substract ) {
      QImage qImage(big.size().width() ,big.size().height(),QImage::Format_RGB32);
      qImage.fill(Qt::blue);
      QPainter *p = new QPainter();
      p->begin(&qImage);
      p->setPen(QPen(Qt::black,5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); /// shadow
      p->setBrush(Qt::white);
      /// p->setPen(Qt::NoPen);
      p->drawRect(QRectF(0,0,big.size().width() - substract , big.size().height() - substract ));
      p->save();
      bool bEnd = p->end();
      if (bEnd) {
          return qImage;
        } else {
          return QImage();
        }
    }
    

  • Qt Champions 2016

    @patrik08 said in Paint shadow inside an QImage or QGraphicsEffect Shadow... html page doc:

    QGraphicsEffect

    Is for all classes that have setGraphicsEffect
    You can cheat
    https://stackoverflow.com/questions/3903223/qt4-how-to-blur-qpixmap-image

    the posts at the end if for Qt5+



  • Tanks ....
    Compiler accept only this way ...... ;-)

    #ifdef QT_NO_GRAPHICSEFFECT
    QImage applyEffectToPics(QImage src, QGraphicsEffect *effect, int extent = 0)
    {
        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, extent*2), 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;
    }
    #endif
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.