本文整理汇总了C++中MyRect::setFlag方法的典型用法代码示例。如果您正苦于以下问题:C++ MyRect::setFlag方法的具体用法?C++ MyRect::setFlag怎么用?C++ MyRect::setFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyRect
的用法示例。
在下文中一共展示了MyRect::setFlag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QGraphicsScene
Game::Game(QWidget* parent){
QGraphicsScene * scene = new QGraphicsScene();
scene->setSceneRect(0,0,800,600);
setBackgroundBrush(QBrush(QImage(":/images/bg4.jpg")));
setWindowTitle("Taiko~");
setScene(scene);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(800,600);
//create the player
MyRect * rect = new MyRect();
// setPixmap(QPixmap(":/images/rect.jpg"));
// rect -> setRect (0,0,10,10);
// rect->setPos(width()/2,height()-rect->rect().height());
rect->setPos(230,235);
//make the player focusable
rect->setFlag(QGraphicsItem::ItemIsFocusable);
rect->setFocus();
// add the rect to the scene
scene->addItem(rect);
//create the score
score = new Score();
score->setPos(40,210);
scene->addItem(score);
//create the time
time = new Time();
time->setPos(42,243);
scene->addItem(time);
//time->countdown ->start();
//spawn enemies
QTimer * timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()),rect,SLOT(spawn()));
timer->start(1000);
}
示例2: main
/*Tutorial:
QGraphicsScene: world, player (Inivisble ~concept)
QGraphicsItem(QGraphicsRectitem): goes into scene
QGraphicsView:
*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//Create a scene
QGraphicsScene *scene = new QGraphicsScene();
//Create an item to put into the scene
MyRect *rect = new MyRect();
rect->setRect(0,0,100,100); //(x,y,width,height)
//Add item to the Scene
scene->addItem(rect);
//Make Rect focusable
rect->setFlag(QGraphicsItem::ItemIsFocusable); //Only one focused item at a time
//Allowing rect to be focusable
rect->setFocus(); //Setting rect item to focus
//Add a view
QGraphicsView *view = new QGraphicsView(scene); //Initializing in constructor
//view->setScene(scene); alternative
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->show();
view->setFixedSize(800,600);
scene->setSceneRect(0,0,800,600);
rect->setPos(view->width()/2,view->height() - rect->rect().height());
//Spawn Enemies
QTimer *timer = new QTimer();
QObject::connect(timer,SIGNAL(timeout()),rect,SLOT(spawn()));
timer->start(2000);
return a.exec();
}
示例3: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Create a scene
QGraphicsScene * mygamescene = new QGraphicsScene();
MyRect * player = new MyRect();
player->setRect(0,0,50,50);
mygamescene->addItem(player);
// Make rect respond to events
player->setFlag(QGraphicsItem::ItemIsFocusable);
player->setFocus();
QGraphicsView * myview = new QGraphicsView(mygamescene);
myview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
myview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
myview->show();
myview->setFixedSize(800,600);
mygamescene->setSceneRect(0,0,800,600);
player->setPos((myview->width()-player->rect().width())/2,myview->height()-player->rect().height());
return a.exec();
}
示例4: 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);
}