QT中手动调用画家事件

QPainter类

 ------------------------------------------------------------------

 图片比例缩放:pix.scaled(pix,width()*0.5,pix,height()*0.5);

----------------------------------------------------------------

void Widget::paintEvent(QPaintEvent *event)
{

//    QPainter painter(this);   //实例化画家对象,this指定的是绘图设备

//    QPen pen(Qt::red);
//    painter.setPen(pen);

//    QBrush brush(Qt::cyan);
//    brush.setStyle(Qt::Dense7Pattern);
//    painter.setBrush(brush);

//    painter.drawLine(QPoint(0,0),QPoint(100,100));

//    painter.drawEllipse(QPoint(100,100),50,50);

//    painter.drawText(QRect(100,200,200,50),"好好学习,天天向上");


    //--------------------------------
    QPainter painter(this);   //实例化画家对象,this指定的是绘图设备
    painter.drawPixmap(pox,100,QPixmap(":/pikaqiu.gif"));

}

手动调用 用update();

----------------------------------------------------------------
    //pixmap绘图设备,
    QPixmap pix(300,300);
    //填充颜色
    pix.fill(Qt::white);
    //声明画家
    QPainter pt(&pix);
    pt.setPen(QPen(Qt::red));
   // pt.drawEllipse(QPoint(150,150),100,100);

    pt.drawPixmap(pox,100,QPixmap(":/pikaqiu.gif"));

    //保存
    pix.save("D:\\aaaaaaa.png");
    
    
    //QImage 绘图设备   可以对像素点进行访问
    QImage img(300,300,QImage::Format_ARGB32);   

    QPainter painter(this);
    //利用QImage对像素进行修改
    QImage img;
    img.load(":/a.png");   //加载图片

    for(int i = 70 ; i <150 ;i++)
    {
        for(int j = 70 ; j<150;j++)
        {
            //修改像素点
            QRgb value = qRgb(255,0,0);
            img.setPixel(i,j,value);
        }
    }
    painter.drawImage(0,0,img);  //画图
------------------------------------------------------------------
QPicture 记录和重现指令
//-----------------------------------
QPaintDevice 绘图设备
QPixmap QImage QBitmap(黑白色) QPicture QWidget
1.QPixmap pix(300,300);
pix.fill(填充颜色);
利用画家往pix上画画 QPainter painter(&pix);
保存 pix.save("路径");
2.QImage可以对像素进行访问
QImage img(300,300,QImage::Format_ARGB32);      
   QPainter painter(this);
对像素进行修改img.setPixel(0,0,value);
3.QPicture 记录和重现
  QPicture pic
  painter.begin(pic);
保存 pic.save(任意后缀名);
重现 利用画家可以重现painter.drawPicture(0,0,pic);
posted @ 2021-10-04 10:37  A_Powered  阅读(148)  评论(0编辑  收藏  举报