QPainter: move that painted



  • Hi there.

    Have followed code:
    @
    void ImageProgressBar::paintEvent(QPaintEvent *event)
    {
    if (value() > minimum())
    {
    QImage tempFrameImage = *frameImage;
    QPainter framePainter(&tempFrameImage);

        framePainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
    
        QRect progressRect = progressImage->rect();
    
        if (value() < maximum())
            progressRect.setWidth((((double)value()/maximum()*100)*tempFrameImage.width()/100));
        else
            progressRect.setWidth(tempFrameImage.width());
    
        framePainter.drawImage(progressRect, *progressImage);
    
        QPainter painter(this);
        painter.drawImage(event->rect(), tempFrameImage);
    }
    else
    {
        QPainter painter(this);
        painter.drawImage(event->rect(), *frameImage);
    }
    

    }
    @
    There is possible to move all that painted after framePainter.drawImage(progressRect, *progressImage);?

    Now I have this result:
    !http://s2.ipicture.ru/uploads/20130914/9dRW9Z53.png(Result)!
    As you can see at left side progress picture above frame picture (same in right side, when progress have 100%). I want to move clipped progress pictore.

    P.S. I have tried making same progress bar via style sheets, but don't found how to clip progress picture only at left and right side of frame picture.

    P.S.S. Qt 4.8.5



  • Found not elegant but working solution:
    @
    void ImageProgressBar::paintEvent(QPaintEvent *event)
    {
    if (value() > minimum())
    {
    QImage tempFrameImage = *frameImage;
    QPainter framePainter(&tempFrameImage);

        framePainter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
    
        QRect progressRect = progressImage->rect();
    
        if (value() < maximum())
            progressRect.setWidth((((double)value()/maximum()*100)*tempFrameImage.width()/100));
        else
            progressRect.setWidth(tempFrameImage.width());
    
        framePainter.drawImage(progressRect, *progressImage);
    
        QPainter painter(this);
        painter.drawImage(event->rect(), *frameImage);
    
        painter.setClipping(true);
        painter.setClipRect(progressRect);
    
        progressRect = event->rect();
        progressRect.setX(1);
        progressRect.setWidth(progressRect.width()-1);
    
        painter.drawImage(progressRect, tempFrameImage);
    }
    else
    {
        QPainter painter(this);
        painter.drawImage(event->rect(), *frameImage);
    }
    

    }
    @
    If someone show me better solution I'll be grateful.


Log in to reply
 

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