• 3328阅读
  • 3回复

QWidget中图片重新绘制的问题 [复制链接]

上一主题 下一主题
离线daxianlcl
 

只看楼主 倒序阅读 楼主  发表于: 2009-06-08
本人写了一个程序,在窗口中加一个QWidget,用于显示图片。一但进行某个操作就会改变图片,可是每次都改变不了。
代码:
#include "mywidget.h"
#include "datetime.h"
#include <QPainter>

MyWidget::MyWidget(QWidget *parent)
        : QWidget(parent)
{
    resize(200, 200);
    image = new QImage(":/image/image/bigtimezone_map.gif");
}

void MyWidget::setOffset(int offset)
{
    this->offset = offset;
    int perSecPix = (image->width())/1440;
    this->x = perSecPix * offset + (image->width() / 4);
    this->y = 0;
}

void MyWidget::paintEvent(QPaintEvent *)
{

    QPainter painter(this);
    painter.drawImage(0, 0, *image, x, y);
}
离线daxianlcl

只看该作者 1楼 发表于: 2009-06-08
自己顶自己
离线duduqq

只看该作者 2楼 发表于: 2009-06-08
painter.drawImage(0, 0, *image, x, y);
应该把"*"去掉吧
painter.drawImage(0, 0, image, x, y);
离线mmmou2000
只看该作者 3楼 发表于: 2009-06-08
1) 谁调用void MyWidget::setOffset(int offset)?
2)在void MyWidget::setOffset(int offset)
  {
     // your codes
    
     update(); // update the view
   }
快速回复
限100 字节
 
上一个 下一个