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. Fast Painting region by region
QtWS25 Last Chance

Fast Painting region by region

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.2k Views
  • 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.
  • A Offline
    A Offline
    aureshinite
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aureshinite
      wrote on last edited by
      #2

      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.

      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