QT 翻金币游戏知识总结
QT翻金币游戏的资料,下载于b站的黑马程序员QT课程,游戏目标为将金币都翻转为同一个颜色(金色)。
资料下载:https://pan.baidu.com/s/12AvEgy3kMORfM93QFA_PKg
提取码:1256
1、void QWidget::setFixedSize(int w, int h)
Sets the width of the widget to w and the height to h.给定窗口固定的宽度和高度
2、void QWidget::setFixedSize(const QSize &s)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.
可以设置窗口最大与最小尺寸
3、 connect(ui->actionQuit,&QAction::triggered,[=](){
this->close();});//此处首先省略了receiver: this, [=](){this->close();} 用了lambda表达式实现槽函数,lambda表达式知识链接如下,http://c.biancheng.net/view/3741.html
4、MypushButton *startBtn =new MypushButton(":/res/MenuSceneStartButton.png",""); //给按钮添加图片
5、startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);//其将图片的左侧放置于this->width(),this->height()*0.7 位置,所以需要-startBtn->width()*0.5,才可把开始按钮放在中心
6、 QSound *startSound = new QSound(":/res/TapButtonSound.wav",this);
startSound->play();
//添加及播放音频
7、
void MypushButton::zoom1()
{
QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
animation->setDuration(200);
animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
animation->setEasingCurve(QEasingCurve::OutBounce);
animation->start();
} //动画
8、 QTimer::singleShot(500,this,[=]() //延时500ms 调用槽函数 此处的槽函数使用lambda表达 式。
{
this->hide();
chooseScene->show();
});
9、 connect(chooseScene,&ChooseLevelSence::chooseSceneBack,[=](){
this->show();
});
signals:
void chooseSceneBack();
//自己定义一个信号 在适当的时机发射信号 发射调用emit函数
使用时:
QTimer::singleShot(<