Hi everyone. I am a newbie in Qt and I have a question.

So I created a new project of QMainWindows. Then I go directly to Forms -> mainwindow.ui and drag Graphics View into the main window. The next thing that I want to do is to add a rectangle inside the graphicView (name of the QGraphicView object) and make it move around just as I want it to be. Any suggestions on how to do that?

I want to make the animation inside the MainWindow, not in another window. I have tried creating scene and trying to put in by code in the mainwindow.cpp (as below), but it doesn't work. If i was able to put the rectangle into the scene/view, i can move to animating the rectangle. But i'm still stuck here.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6.  
  7. //create a scene
  8. QGraphicsScene * scene = new QGraphicsScene();
  9.  
  10. //create the rectangle
  11. rect->setRect(0,0,50,50);
  12.  
  13. //add the item into the scene
  14. scene->addItem(rect);
  15.  
  16. //use the view from the mainwindow
  17. graphicsView = new QGraphicsView(scene);
  18. graphicsView.show();
  19.  
  20. }
To copy to clipboard, switch view to plain text mode 

I have randomly tried including "ui_mainwindow.h" but it still doesn't work. Haha