SHARE
TWEET

Untitled

a guest Aug 14th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. auto scene = new QGraphicsScene;
  2. auto graphicsView = new QGraphicsView { scene };
  3. setCentralWidget(graphicsView);
  4.  
  5. auto sky = scene->addPixmap(QStringLiteral(":/icons/sky.png"));
  6. std::array<QGraphicsItem *, 6> items = {
  7.    scene->addPixmap(QStringLiteral(":/icons/clouds_1.png")),
  8.    scene->addPixmap(QStringLiteral(":/icons/clouds_2.png")),
  9.    scene->addPixmap(QStringLiteral(":/icons/clouds_3.png")),
  10.    scene->addPixmap(QStringLiteral(":/icons/rocks_1.png")),
  11.    scene->addPixmap(QStringLiteral(":/icons/clouds_4.png")),
  12.    scene->addPixmap(QStringLiteral(":/icons/rocks_2.png"))
  13. };
  14. scene->setSceneRect(sky->boundingRect());
  15. graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  16. graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  17. setFixedSize(sky->boundingRect().size().toSize());
  18.  
  19. connect(&_timer, &QTimer::timeout, this, [items, sky](){
  20.    for (int i = 0; i < 6; ++i)
  21.       items[i]->setX(items[i]->x() > -sky->boundingRect().width() ? items[i]->x()-(i+1):0);
  22. });
  23. _timer.start(1000 / 33);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top