本文整理汇总了C++中MyRect::setRect方法的典型用法代码示例。如果您正苦于以下问题:C++ MyRect::setRect方法的具体用法?C++ MyRect::setRect怎么用?C++ MyRect::setRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyRect
的用法示例。
在下文中一共展示了MyRect::setRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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();
}