release下的exe文件流畅度要远好于debug下的exe文件。
源码来源:基于Qt5模拟企业微信聊天界面(QWidget)_阿木大叔mu的博客-CSDN博客
初看时,觉得很神奇,猫眼会随着鼠标移动。
看完源码后,感觉很精美。
全是用painter画上去的,全是画pixmap。
关于画猫,画起来其实对我来说很困难。
他的源码如下:
先偏移(translate),再等比例缩放(scale)
之后就相当于在1920*1080大小的空间画图了。(因为图片是1920*1080像素的)
之后就是扣位置了。(我做不到这么细致)
通过改变参数m_fXRadio,m_fYRadio的大小改变眼睛的位置。
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
painter->translate(rectMain.left(), rectMain.top());
painter->scale(rectMain.width() / 1920.0, rectMain.height() / 1080.0);
QRect rcImgRain(0, 0, 1920, 1080);//彩虹
QPixmap pRain = m_pixRain.scaled(rcImgRain.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgRain, pRain);
QRect rcImgEyeBg(730, 335, 283, 162);//眼背景(黄)
QPixmap pImgEyeBg = m_pixCatEyeBg.scaled(rcImgEyeBg.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgEyeBg, pImgEyeBg);
//眼黑左
QRect rcImgEyeBlackLeft(730 + 120 * m_fXRadio - 80 / 2, 335 + 120 * m_fYRadio - 82 /2, 80, 82);
QPixmap pImgEyeBlack = m_pixCatEyeBlack.scaled(rcImgEyeBlackLeft.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgEyeBlackLeft, pImgEyeBlack);
//眼白左
QRect rcImgEyeWriteLeft(rcImgEyeBlackLeft.left() + 16, rcImgEyeBlackLeft.top() + 16, 20, 20);
QPixmap pImgEyeWriteLeft = m_pixCatEyeWhite.scaled(rcImgEyeWriteLeft.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgEyeWriteLeft, pImgEyeWriteLeft);
QRect rcImgEyeBlackRight(895 + 120 * m_fXRadio - 80 / 2, 387 + 120 * m_fYRadio - 82 /2, 80, 82);
pImgEyeBlack = m_pixCatEyeBlack.scaled(rcImgEyeBlackRight.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgEyeBlackRight, pImgEyeBlack);
QRect rcImgEyeWriteRight(rcImgEyeBlackRight.left() + 16 , rcImgEyeBlackRight.top() + 16, 20, 20);
QPixmap pImgEyeWriteRight = m_pixCatEyeWhite.scaled(rcImgEyeWriteRight.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgEyeWriteRight, pImgEyeWriteRight);
QRect rcImgCat(0, 0, 1920, 1080);
QPixmap p = m_pixCat.scaled(rcImgCat.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawPixmap(rcImgCat, p);
painter->restore();