Yes it does.
One might conjecture, though, that none of them qualify as "simple", let alone "very simple". :-)
Added after 12 minutes:
Of additional interest, I tried another one of the "answers" which had been posted to a similar question:
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
item->setRect( -50.0, -50.0, 100.0, 100.0 );
view.
setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
QGraphicsItem *item = new QGraphicsEllipseItem( 0, &scene );
item->setRect( -50.0, -50.0, 100.0, 100.0 );
QGraphicsView view( &scene );
view.setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
The compiler complained about the two lines:
item->setRect( -50.0, -50.0, 100.0, 100.0 );
QGraphicsItem *item = new QGraphicsEllipseItem( 0, &scene );
item->setRect( -50.0, -50.0, 100.0, 100.0 );
To copy to clipboard, switch view to plain text mode
But, when I replaced them with:
scene.addItem(item);
QGraphicsItem *item = new QGraphicsEllipseItem( -50.0, -50.0, 100.0, 100.0, Q_NULLPTR );
scene.addItem(item);
To copy to clipboard, switch view to plain text mode
it compiled, ran, and produced a very nice ellipse (circle) inside the QGraphicsView.
One further question though: The compile output ended with "exited normally". But, within the output, it had reported:
del release\moc_mainwindow.cpp
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\release\moc_mainwindow.cpp
del ui_mainwindow.h
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\ui_mainwindow.h
del release\main.o release\mainwindow.o release\moc_mainwindow.o
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\release\main.o
del release\moc_mainwindow.cpp
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\release\moc_mainwindow.cpp
del ui_mainwindow.h
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\ui_mainwindow.h
del release\main.o release\mainwindow.o release\moc_mainwindow.o
Could Not Find C:\work\Qt5Work\Qt570\LearningTests\build-QGraphicsViewFirstTest-Desktop_Qt_5_7_0_MinGW_32bit-Debug\release\main.o
To copy to clipboard, switch view to plain text mode
One wonders why it reported that it couldn't find an item immediately after it had reported that it had just deleted that item ??
And, one final question: Since this last example, as corrected, satisfies my request for a very simple example, I'm going to post it here in its complete final form.
How do I then mark this thread as "SOLVED" so it might be helpful to others?
Added after 20 minutes:
SOLUTION
The following very simple example (as main.cpp) compiled, ran, and displayed a very nice ellipse (circle) in the QGraphicsView on my Qt 5.7.0 MinGW 32-bit QtCreator 4.0.2 installation running on Windows 7 Pro SP1:
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
scene.addItem(item);
view.
setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
int main( int argc, char **argv )
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
QGraphicsItem *item = new QGraphicsEllipseItem( -50.0, -50.0, 100.0, 100.0, Q_NULLPTR );
scene.addItem(item);
QGraphicsView view( &scene );
view.setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks