I'd like to write very simple game.
Here's a part of code:
Qt Code:
  1. QGraphicsPixmapItem *pixmap=scene->addPixmap(QPixmap("img.png"));
  2. ui->graphicsView->setScene(scene);
To copy to clipboard, switch view to plain text mode 
pixmap is a creature that can be moved by player using WSAD keys.
I did it by this way:
Qt Code:
  1. void MainWindow::keyPressEvent(QKeyEvent *event){
  2. switch(event->key()){
  3. case Qt::Key_D:
  4. pixmap->setPos(pixmap->pos().x()+1, pixmap->pos().y());
  5. break;
  6. case Qt::Key_A:
  7. pixmap->setPos(pixmap->pos().x()-1, pixmap->pos().y());
  8. break;
  9. (...)
  10. }
  11. }
To copy to clipboard, switch view to plain text mode 
Now i want to prevent pixmap from being moved out of QGraphicsView.
How can I do it?
Thanks in advance.