コード例 #1
0
// run - paint the QImage
void timeConsumingThread::run()
{
   int i_ctr = 60;
   int j_ctr = 60;
   QImage myQImage(i_ctr, j_ctr, QImage::Format_RGB32);
   QPainter painter(&myQImage);
   for (int nMainCounter = 0; nMainCounter < 1000; nMainCounter++)
   {
    for (int i=0; i<i_ctr; i++)
    {
      for (int j=0; j<j_ctr; j++)
      {
         double hue = (double)(i + j + i*j)/361200.0;
         QColor myColor;
         myColor.setHsvF(hue, 1.0, 1.0, 1.0);
         painter.setPen(myColor);
         painter.drawPoint(i, j);
      }
    }   
    // emit theImage(myQImage);
    int x = GetRNDValue(0, 600);
    int y = GetRNDValue(0, 600);
    emit theImage(QRect(x, y, i_ctr, j_ctr), myQImage);
   }
}
コード例 #2
0
ファイル: worker.cpp プロジェクト: MakSim345/QT-Dev
void Worker::run()
{
    // Note: this is never called directly. It is called by Qt once the 
    // thread environment has been set up        
    // random.seed();
    int n = stars;
    int m_width = m_size.width();
    int m_height= m_size.height();
        
    do {
        QImage image = QImage(outerRadius * 2, outerRadius * 2, QImage::Format_ARGB32);
        image.fill(qRgba(255, 255, 256, 0));
            
        int x = GetRNDValue(0, m_width);
        int y = GetRNDValue(0, m_height);
        
        int angle = GetRNDValue(0, 360);
        int red = GetRNDValue(0, 256);
        
        int green = GetRNDValue(0, 256);
        int blue = GetRNDValue(0, 256);
        int alpha = GetRNDValue(0, 256);
        /*
        QPainter *painter = new QPainter();
        painter->begin(&image);
        painter->setRenderHint(QPainter::Antialiasing);
        painter->setPen(Qt::NoPen);
        painter->setBrush(QColor(red, green, blue, alpha));
        painter->translate(outerRadius, outerRadius);
        painter->rotate(angle);
        painter->drawPath(path);
        painter->end();
        */       

        //-----------
       QImage myQImage(60, 60, QImage::Format_RGB32);
       QPainter painter1(&myQImage);
        for (int i=0; i<60; i++)
        {
            for (int j=0; j<60; j++)
            {
                double hue = (double)(i + j + i*j)/361200.0;
                QColor myColor;
                myColor.setHsvF(hue, 1.0, 1.0, 1.0);
                painter1.setPen(myColor);
                painter1.drawPoint(i, j);
            }
        }
        //-----------

        emit output (QRect(x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2), myQImage);
        
        sleep(0.01);
        n --;
        qDebug("Iteration number %d\n", n);
    } while ((!exiting) && (n > 0));
}