[Kde-devel-es] QT 4.0.1 - QPainter lento

Ezequiel Solares scofmm at gmail.com
Wed Oct 26 12:59:28 CEST 2005


Hola

Estoy intenteando hacer un programa que funcione 
como un oscilioscopio, pero es muy lento el 
dibujo de la señal (por el momento considero el 
mouse). ¿alguien podria mirarlo y decirme como hacerlo mas rapido?
En las qt 4.0.1 no hay bitblit, por lo que 
drawPixmap es la forma de copiar un QPixmap a QPainter.

Aqui esta el codigo, si alguien quiere todo el codigo que avise no mas.



#include <QPainter>
#include <QMouseEvent>
#include <QPixmap>
#include <QPen>
#include <QTimer>
#include <QList>

#include "qmywidget.h"

QMyWidget::QMyWidget(QWidget *parent)
     : QWidget(parent)
         , m_pix(parent->width(), parent->height())
{
//      paintObj.begin(this);
         setMouseTracking(true);
         posX=0; posExY=-1;
//      startTimer(0);
         QTimer *timer1 = new QTimer(this);
         connect(timer1, SIGNAL(timeout()), this, SLOT(updPoint()));
         timer1->start(0);
         m_pix.fill(Qt::black);
}

void QMyWidget::updPoint()
{
         newPoint();
         update();
}

void QMyWidget::newPoint()
{
         dataPoint.append(posY);
         if (posX >= width()) {
         } else {
                 posX++;
         }
         int listS, listE;
         QPen pen(Qt::red, 2);

         if (posExY<10) { posExY++; return; }
         posExY = 0;

         QPainter painter(&m_pix);

         painter.setPen(pen);

         if (dataPoint.isEmpty()) return;
         if (posX >= width()) {
                 listS = dataPoint.size() - width();
                 listE = dataPoint.size();
         } else {
                 listS = 0;
                 listE = dataPoint.size();
         }
         // drawPixmap (QPixmap)
         for (int i = listS; i < listE; ++i) {
//              painter.drawPoint(i - listS,dataPoint.at(i));
                 painter.drawRect(i - listS,dataPoint.at(i),2,2);
         }
         painter.end();
}

void QMyWidget::timerEvent( QTimerEvent * )
{
/*      newPoint();
         update();*/
}

void QMyWidget::mouseMoveEvent(QMouseEvent *e)
{
         posY=e->globalY();
}

void QMyWidget::paintEvent(QPaintEvent * /* event */)
{
         QPainter painter;
         painter.begin(this);
         painter.drawPixmap( 0, 0, m_pix );
}



More information about the Kde-devel-es mailing list