本文整理汇总了C++中MyRect::rect方法的典型用法代码示例。如果您正苦于以下问题:C++ MyRect::rect方法的具体用法?C++ MyRect::rect怎么用?C++ MyRect::rect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyRect
的用法示例。
在下文中一共展示了MyRect::rect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例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: mousePressEvent
void RectScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPointF pos = event->scenePos();
MyRect * item = dynamic_cast<MyRect *>(itemAt(pos,QTransform()));
switch (mode)
{
case Add:
{
buffer.push_back(pos);
if (buffer.size() == 2)
{
MyRect * newrect = new MyRect(buffer[0],buffer[1]);
addItem(newrect);
buffer.clear();
newrect->label = giveName(namePool++);
auto x = new QGraphicsTextItem(newrect->label,newrect);
x->setPos(newrect->rect().center());
treescene->tree->insert(newrect->entry);
update();
treescene->drawTree();
}
}
break;
case Remove:
{
if (item)
{
removeItem(item);
treescene->tree->deleteEntry(item->entry);
delete item;
update();
treescene->drawTree();
}
}
break;
case Search:
{
if (!insearch)
{
insearch = true;
buffer.push_back(pos);
}
else
{
insearch = false;
QRectF rect(pos,buffer[0]);
searchBuf.push_back(new QGraphicsRectItem(rect));
addItem(searchBuf.back());
deque<LeafEntry*> x = treescene->tree->searchOverlap(to2D(rect));
MyRect * rectpt;
int n = x.size();
for (int i = 0; i<n; ++i)
{
rectpt =(MyRect*) x[i]->data;
rectpt->setSelected(true);
}
buffer.clear();
}
}
break;
}
}