工程承包去哪个网站,女性时尚资讯+淘宝客模式系列网站源码,模板网站的弊端,网页版梦幻西游嗜血狂魔攻略目录
1.主场景搭建
1.1重载绘制事件#xff0c;绘制背景图和标题图片
1.2设置窗口标题#xff0c;大小#xff0c;图片
1.3退出按钮对应关闭窗口#xff0c;连接信号
2.开始按钮创建
2.1封装MyPushButton类
2.2加载按钮上的图片
3.开始按钮跳跃效果
3.1按钮向上跳…目录
1.主场景搭建
1.1重载绘制事件绘制背景图和标题图片
1.2设置窗口标题大小图片
1.3退出按钮对应关闭窗口连接信号
2.开始按钮创建
2.1封装MyPushButton类
2.2加载按钮上的图片
3.开始按钮跳跃效果
3.1按钮向上跳动
3.2按钮向下跳动 1.主场景搭建
1.1重载绘制事件绘制背景图和标题图片
void MainScene::paintEvent(QPaintEvent *event)
{QPainter painter(this);QPixmap pix;//背景图pix.load(:/CoinRes/2.png);painter.drawPixmap(0,0,this-width(),this-height(),pix);//加载图片pix.load(:/CoinRes/2.png);//缩放图片pixpix.scaled(pix.width()*0.5,pix.height()*0.5);painter.drawPixmap(10,30,pix.width(),pix.height(),pix);
}
1.2设置窗口标题大小图片
MainScene::MainScene(QWidget *parent): QMainWindow(parent), ui(new Ui::MainScene)
{ui-setupUi(this);//设置固定大小this-setFixedSize(320,580);//设置应用图片this-setWindowIcon(QPixmap(:/CoinRes/1.png));//设置窗口标题this-setWindowTitle(翻金币游戏);
}
1.3退出按钮对应关闭窗口连接信号 //退出按钮退出程序connect(ui-actionQuit,QAction::triggered,[]{this-close();});
2.开始按钮创建
需求如下开始按钮初始时为一个图片按下显示为另一个图片 2.1封装MyPushButton类
class MyPushButton : public QPushButton
{Q_OBJECT
public:explicit MyPushButton(QWidget *parent nullptr);MyPushButton(QString normalImg,QString pressImg);//默认显示图片路径QString normalImgPath;//按下后显示的图片路径QString pressedImgPath;signals:};
2.2加载按钮上的图片
MyPushButton::MyPushButton(QString normalImg, QString pressImg)
{normalImgPathnormalImg;pressedImgPathpressImg;QPixmap pix;bool retpix.load(:/CoinRes/1.png);if(falseret){qDebug()normalImg图片加载失败;}//设置图片的固定尺寸this-setFixedSize(pix.width(),pix.height());//设置不规则图片的样式表将背景多余部分取消掉this-setStyleSheet(QPushButton{border:0px;});//设置图标this-setIcon(pix);//设置图标大小this-setIconSize(QSize(pix.width(),pix.height()));
}
3.开始按钮跳跃效果
需求按钮点击后可以向上向下跳动
3.1按钮向上跳动
void MyPushButton::zoom1()
{//创建动画对象在当前按钮用几何图形QPropertyAnimation* animation1new QPropertyAnimation(this,geometry);//设置动画的维持时间animation1-setDuration(200);//设置起始位置animation1-setStartValue(QRect(this-x(),this-y(),this-width(),this-height()));//设置结束位置animation1-setEndValue(QRect(this-x(),this-y()10,this-width(),this-height()));//设置缓和曲线设为弹跳效果animation1-setEasingCurve(QEasingCurve::OutBounce);//开始执行动画设置属性动画执行结束后销毁对象animation1-start(QAbstractAnimation::DeleteWhenStopped);
}
3.2按钮向下跳动
void MyPushButton::zoom2()
{//创建动画对象在当前按钮用几何图形QPropertyAnimation* animation1new QPropertyAnimation(this,geometry);//设置动画的维持时间animation1-setDuration(200);//设置起始位置animation1-setStartValue(QRect(this-x(),this-y()10,this-width(),this-height()));//设置结束位置animation1-setEndValue(QRect(this-x(),this-y(),this-width(),this-height()));//设置缓和曲线设为弹跳效果animation1-setEasingCurve(QEasingCurve::OutBounce);//开始执行动画设置属性动画执行结束后销毁对象animation1-start(QAbstractAnimation::DeleteWhenStopped);
}