Fast Painting region by region



  • I need to paint on my widget region by region and I want to get some suggestion on how to do so in the most efficient way possible. I have a video playing by my custom player, let's say at a rate around 5fps to 30 fps. On top of the display I have another widget I use as overlay, which receive information about each 16x16 blocks of pixels. For each of this block I need to apply a transparent color and vector.

    Right now I have the following method called inside paint event:

    @
    void OverlayDrawer::drawVectors(QPainter painter){
    int x,y;
    int vx,vy;
    QLineF line1,line2,line3;
    QVector<QLineF> arraylines;
    BLOCK
    blk;

    float ratiox = 1;//((float)width())/defaultSize.width();  don't mind this, it is just in case of resizing
    float ratioy = 1;//((float)height())/defaultSize.height();
    float arrowsize = 3.0f*(ratiox+ratioy)/2;
    
    QListIterator<BLOCK*> mbIterator(pictureInformation.blockList()); // get list of block info
    while(mbIterator.hasNext()){
        blk = mbIterator.next();
        x = blk->X();
        y = blk->Y();
    
        vx = blk->vectorX();
        vy = blk->vectorY();
    
        // cellsize = 16x16 when the screen is not resized
       // I also draw the rectagle (not displayed here), that's why there is a QrectF
         QRectF rect(x*cellsize.width(),y*cellsize.height(),cellsize.width(),cellsize.height()); 
         makeArrow(QPointF(rect.center().x() +vx*ratiox  ,rect.center().y()+vy*ratioy),
            QPointF(rect.center().x(), rect.center().y()),
            arrowsize,
            line1,
            line2,
            line3
            );
    

    if (!qFuzzyCompare(line1.length(), qreal(0.))){
    arraylines.append(line1);
    arraylines.append(line2);
    arraylines.append(line3);
    }
    }
    painter->setPen(Qt::blue);
    painter->setRenderHint(QPainter::Antialiasing);
    painter->drawLines(arraylines);
    }
    @

    I want to optimize this as much as possible. I already thought about computing (makeArrow())all the arrows at construction, and only creating the appropriate ones by translation. But I want to know the BEST TOOL in the framework for this kind of task. Is it openGL, some function I didn't notice? etc.. etc..
    Thanks



  • For those who might be interested I figured out a simple way :

    • Drawing outside the paint event in a picture with alpha enabled

    • Painting the picture on top of the video. Which means before displaying the actual video, I paint the overlay image on the video image. Now I dropped superposition of child widgets and everything.

    The advantage is that I can create the overlay while the application is busy doing some other things.


Log in to reply
 

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