当前位置: 首页>>代码示例>>C++>>正文


C++ MyRect::pixmap方法代码示例

本文整理汇总了C++中MyRect::pixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ MyRect::pixmap方法的具体用法?C++ MyRect::pixmap怎么用?C++ MyRect::pixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyRect的用法示例。


在下文中一共展示了MyRect::pixmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QWidget

/* GameBored contstructor
 * @param QWidget is the parent widget
*/
GameBored::GameBored(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::GameBored)
{
    ui->setupUi(this);

    // make scene
    QGraphicsScene * scene= new QGraphicsScene();
    scene->setSceneRect(0,0,800,600);
    scene->setBackgroundBrush(QBrush(QImage(":/pics/bg")));


    // make and add item to scene
    MyRect * player = new MyRect();
    scene->addItem(player);

    // focus item so that it can receive keyboard events
    player->setFlag(QGraphicsItem::ItemIsFocusable);
    player->setFocus();


    // add scene to new view
    QGraphicsView * view = new QGraphicsView(scene);

    //turn off scrollbars
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


    Board= new QWidget;
    //Board->setFixedSize(400,400);

    // add view to new layout
    // add layout to central widget
    QVBoxLayout * vlayout = new QVBoxLayout(Board);
    vlayout->addWidget(view);
    this->setLayout(vlayout);

    //
    this->show();
    view->setFixedSize(800,600);
    scene->setSceneRect(0,0,800,600);

    player->setPos(view->width()/2 -player->pixmap().width()/2, -28 /*view->height()- player->pixmap().height()*/);

    // constant creation of enemies
    QTimer* timer = new QTimer();
    QObject::connect(timer,SIGNAL(timeout()),player,SLOT(spawn()));
    timer->start(2400);

    QTimer* timer2 = new QTimer();
    QObject::connect(timer2,SIGNAL(timeout()),player,SLOT(spawn2()));
    timer2->start(5000);


    // play music
    mp3player = new QMediaPlayer();
    mp3player->setMedia(QUrl("qrc:/audio/starfox.mp3"));
    mp3player->play();

    // add score class to screen
    score = new Score();
    scene->addItem(score);
}
开发者ID:aslanmpour,项目名称:Repository,代码行数:67,代码来源:gamebored.cpp


注:本文中的MyRect::pixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。