现在的位置: 首页 > 综合 > 正文

Qt组件中的双缓冲无闪烁绘图

2013年10月30日 ⁄ 综合 ⁄ 共 410字 ⁄ 字号 评论关闭

闪烁首先,要想把闪烁减弱,请设置组件的背景模式为NoBackground.
setBackgroundMode(NoBackground);

其次,重载组件的paintEvent()函数,如下改写:
void MyWidget::paintEvent(QPaintEvent *e)
{
QRect ur=e->rect();//得到组件尺寸
QPixmap pix(ur.size());//以此为参数创建一个位图变量
pix.fill(this,ur.topLeft());//填充位图
QPainter p(&pic);//以位图为参数创建一个QPainter 对象

p.translate(-ur.x(),-ur.y());//在QPainter 上绘画
//......//Drawing

p.End();//绘画完毕

bitBlt(this,ur.topLeft().&pix);//把位图贴到组件上
}

junglesong 整理
2004-1-24  

抱歉!评论已关闭.