Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include "game.h"
  2. #include "ui_game.h"
  3. #include <QGraphicsScene>
  4. #include <QGraphicsView>
  5. #include <QGraphicsRectItem>
  6. #include <QPushButton>
  7.  
  8. Game::Game(QWidget *parent) :
  9. QMainWindow(parent),
  10. scene(new QGraphicsScene(this)),
  11. view(new QGraphicsView(scene, this)))
  12. {
  13.  
  14. // Add to the window
  15. this->setCentralWidget(view);
  16.  
  17. // Scene
  18. scene->setSceneRect(0, 0, 800, 600); // Origin of the view
  19.  
  20. // View
  21. view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  22. view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  23. view->setFixedSize(800, 600);
  24.  
  25. renderMenu();
  26. }
  27.  
  28. Game::~Game()
  29. {
  30. }
  31.  
  32. void Game::renderMenu()
  33. {
  34. scene->clear();
  35. // Create Rectangle
  36. QGraphicsRectItem * rect = new QGraphicsRectItem();
  37. rect->setRect(20, 50, 100, 100);
  38. scene->addItem(rect);
  39.  
  40. QPushButton * btn = new QPushButton(QString("Test"));
  41. scene->addWidget(btn);
  42. connect(btn, SIGNAL(clicked(bool)), this, SLOT(renderGame()));
  43. }
  44.  
  45. void Game::renderGame()
  46. {
  47. scene->clear();
  48. // Create Rectangle
  49. QGraphicsRectItem * rect2 = new QGraphicsRectItem();
  50. rect2->setRect(20, 50, 200, 120);
  51. scene->addItem(rect2);
  52.  
  53. QPushButton * btn = new QPushButton(QString("Test2"));
  54. scene->addWidget(btn);
  55. connect(btn, SIGNAL(clicked(bool)), this, SLOT(renderMenu()));
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement