ccloolcc 发表于 2009-2-4 17:15:00

pixmap 映射到 widget 无效到问题

void DrawWidget::paintEvent( QPaintEvent *)
{
   
static QPixmap    pix(320,240);
pix.fill( this, 320, 240 );

QPainter paint(&pix);
   for(int i= 0; i<count-1;i++){
int j = i+1;
paint.drawLine( points, points );


   }

    bitBlt( this, 320, 240, &pix );
   
}
这是我的部分代码,问题就出在这里,
QPainter paint(this)时,this为widget,代码有效,但update后所画的图就消失,所以决定采用映射到pixmap的方法
QPainter paint(&pix)时,画图没反映,映射失败,那位知道原因请告诉小弟 谢谢了
下面是所有代码:
#include <qwidget.h>
#include <qpainter.h>
#include <qpicture.h>
#include <qpixmap.h>
#include <qlabel.h>
#include <qstring.h>
#include <qapplication.h>
#include <math.h>
const int MAXPOINTS = 2000;
class DrawWidget:public QWidget
{
public:
   DrawWidget(QWidget *parent = 0, const char *name= 0);
   
protected:
    void drawIt( QPainter * );
    void paintEvent( QPaintEvent * );
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
private:
    void drawFonts(QPainter *p);
int count;
bool down;
QPoint   *points;


};
DrawWidget:editor/images/smilies/default/13.gif{
   
   
   
    setBackgroundColor(white);
points = new QPoint;
count = 0;
    update();
    resize(320, 240);
setMouseTracking(TRUE);
}

void DrawWidget::mouseMoveEvent( QMouseEvent *e)
{
// if (down&&count<MAXPOINTS){
QPainter paint(this);
points = e->pos();
paint.drawPoint(e->pos());

// update();

qDebug("mouseMoveEvent");
// }
}
void DrawWidget::mousePressEvent( QMouseEvent *e)
{

    down = TRUE;
count = 0 ;
// erase();
qDebug("mousePressEvent");
}
void DrawWidget::mouseReleaseEvent( QMouseEvent *)
{
down = FALSE;
update();
}
void DrawWidget::paintEvent( QPaintEvent *)
{
   

static QPixmap    pix(320,240);
pix.fill( this, 320, 240 );
QPainter paint(this);
   for(int i= 0; i<count-1;i++){
int j = i+1;
paint.drawLine( points, points );


   }
    bitBlt( this, 320, 240, &pix );
   
}

void DrawWidget:editor/images/smilies/default/22.gif{
/*
   p->drawLine(1,1,38,38);
   qDebug("paintEvent");
   update ();
   */
}
int main(int argc,char** argv)
{
QApplication app(argc,argv);
DrawWidget w;

app.setMainWidget(&w);
w.show();
return app.exec();
}
页: [1]
查看完整版本: pixmap 映射到 widget 无效到问题