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.
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
//create a scene
//create the rectangle
rect->setRect(0,0,50,50);
//add the item into the scene
scene->addItem(rect);
//use the view from the mainwindow
graphicsView.show();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//create a scene
QGraphicsScene * scene = new QGraphicsScene();
//create the rectangle
QGraphicsRectItem * rect = new QGraphicsRectItem();
rect->setRect(0,0,50,50);
//add the item into the scene
scene->addItem(rect);
//use the view from the mainwindow
graphicsView = new QGraphicsView(scene);
graphicsView.show();
}
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
Bookmarks