魔方网表 让信息化更简单

 找回密码
 注册
查看: 5974|回复: 0

pixmap 映射到 widget 无效到问题

[复制链接]
ccloolcc 发表于 2009-2-4 17:15:00 | 显示全部楼层 |阅读模式
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[j] );
  
  
   }

    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:{
   
   
   
    setBackgroundColor(white);
points = new QPoint[MAXPOINTS];
count = 0;
    update();
    resize(320, 240);
setMouseTracking(TRUE);
}

void DrawWidget::mouseMoveEvent( QMouseEvent *e)
{
// if (down&&count<MAXPOINTS){
QPainter paint(this);
points[count++] = 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[j] );
  
  
   }
    bitBlt( this, 320, 240, &pix );
   
}

void DrawWidget:{
/*
   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();
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|魔方软件 ( 京ICP备08008787号 )

京公网安备 11010702001722号

GMT+8, 2024-4-20 13:08 , Processed in 0.068159 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表