zoukankan      html  css  js  c++  java
  • 打地鼠游戏(7)

    需求:

    1、当移动鼠标到view容器中时,让鼠标样式变为一个锤子抬起的样子

    2、点击时,鼠标样式变为按下的锤子样式

    3、鼠标单击之后抬起时,显式为锤子抬起的样式

    在QWidget中有一个属性:cursor可以定义用户的鼠标样式,可以通过设置这个属性值达到修改鼠标样式:

    查看帮助文档:QCursor

    1 QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX = -1, int hotY = -1)
    2 
    3 QCursor(const QPixmap &pixmap, int hotX = -1, int hotY = -1)

    第一个参数,就是设置一个样式图片,其他参数有默认值。

    对谁的cursor属性进行设置?

    当移动鼠标到图元时(红色框)才需要显示为锤子样式;当移动鼠标到view容器时,如果没有移动到图元上,就不用显示为锤子样式,所以设置图元类:

     1 void myitem::mousePressEvent(QGraphicsSceneMouseEvent *event){
     2 
     3     //修改鼠标样式
     4     this->setCursor(QPixmap(":/bg/pic/picturedown.png"));
     5 
     6     //判断当前是否是老鼠
     7     if(this->ismouse()){
     8         qDebug()<<"打到老鼠";
     9         handle* pt = handle::getinstence();
    10         pt->addscore();
    11 
    12         //避免连续两次打击,从而记分重复
    13         this->setmouse(false);
    14 
    15         //打到老鼠之后更改显示为击中的样式
    16         this->setPixmap(QPixmap(":/mouse/pic/beatmouse.png"));
    17 
    18     }else{
    19         qDebug()<<"未打到老鼠";
    20     }
    21 }
    1 void myitem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){
    2     //修改鼠标样式
    3     this->setCursor(QPixmap(":/bg/pic/pictureUp.png"));
    4 }
     1 void myitem::mousePressEvent(QGraphicsSceneMouseEvent *event){
     2 
     3     //修改鼠标样式
     4     this->setCursor(QPixmap(":/bg/pic/picturedown.png"));
     5 
     6     //判断当前是否是老鼠
     7     if(this->ismouse()){
     8         qDebug()<<"打到老鼠";
     9         handle* pt = handle::getinstence();
    10         pt->addscore();
    11 
    12         //避免连续两次打击,从而记分重复
    13         this->setmouse(false);
    14 
    15         //打到老鼠之后更改显示为击中的样式
    16         this->setPixmap(QPixmap(":/mouse/pic/beatmouse.png"));
    17 
    18     }else{
    19         qDebug()<<"未打到老鼠";
    20     }
    21 }

    内在的趣味,表面的繁琐
  • 相关阅读:
    学习《Building Applications with FME Objects》 之十 使用集合
    oracle左右连接的另外表示方法
    拥抱SQLAlchemy 之二 拉拉手,我请你去看电影~
    Oracle中的Union、Union All、Intersect、Minus
    System.Data.SQLite测试
    SmartSVN + google code
    学习《Building Applications with FME Objects》 之九 高级要素处理
    Django静态文件配置备忘录
    测试oracle with as
    测量坐标系中单个多边形面积解析法计算的程序源代码
  • 原文地址:https://www.cnblogs.com/data1213/p/10852454.html
Copyright © 2011-2022 走看看