• 4187阅读
  • 0回复

pixmap 映射到 widget 无效到问题 [复制链接]

上一主题 下一主题
离线ccloolcc
 
只看楼主 倒序阅读 楼主  发表于: 2009-02-04
— 本帖被 XChinux 执行加亮操作(2009-02-05) —
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();
}
快速回复
限100 字节
 
上一个 下一个