Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "game.h"
- #include "ui_game.h"
- #include <QGraphicsScene>
- #include <QGraphicsView>
- #include <QGraphicsRectItem>
- #include <QPushButton>
- Game::Game(QWidget *parent) :
- QMainWindow(parent),
- scene(new QGraphicsScene(this)),
- view(new QGraphicsView(scene, this)))
- {
- // Add to the window
- this->setCentralWidget(view);
- // Scene
- scene->setSceneRect(0, 0, 800, 600); // Origin of the view
- // View
- view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- view->setFixedSize(800, 600);
- renderMenu();
- }
- Game::~Game()
- {
- }
- void Game::renderMenu()
- {
- scene->clear();
- // Create Rectangle
- QGraphicsRectItem * rect = new QGraphicsRectItem();
- rect->setRect(20, 50, 100, 100);
- scene->addItem(rect);
- QPushButton * btn = new QPushButton(QString("Test"));
- scene->addWidget(btn);
- connect(btn, SIGNAL(clicked(bool)), this, SLOT(renderGame()));
- }
- void Game::renderGame()
- {
- scene->clear();
- // Create Rectangle
- QGraphicsRectItem * rect2 = new QGraphicsRectItem();
- rect2->setRect(20, 50, 200, 120);
- scene->addItem(rect2);
- QPushButton * btn = new QPushButton(QString("Test2"));
- scene->addWidget(btn);
- connect(btn, SIGNAL(clicked(bool)), this, SLOT(renderMenu()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement