C++ (Qt) QGraphicsScene scene = new QGraphicsScene(this); scene.setSceneRect(-300, -300, 300, 300); scene.setItemIndexMethod(QGraphicsScene::NoIndex);
C++ (Qt) for (int i = 0; i < 3; ++i) { Target *target= new Target; scene.addItem(target); }
C++ (Qt) ui->grvMain->setScene(&scene);
C++ (Qt) painter->setBrush(color); painter->drawEllipse(-20, -20, 20, 20);
C++ (Qt)QRectF Target::boundingRect() const{ qreal adjust = 0.5; return QRectF(-18 - adjust, -22 - adjust, 36 + adjust, 60 + adjust);}
C++ (Qt) ui->grvMain->setBackgroundBrush(QPixmap(":/img/map.jpg"));
QGraphicsScene scene = new QGraphicsScene(this);
QGraphicsScene *scene = new QGraphicsScene(this);
C++ (Qt) QGraphicsEllipseItem *pkrug = new QGraphicsEllipseItem(0, scene); pkrug->setPen(QPen(Qt::black)); pkrug->setBrush(QBrush(Qt::yellow)); pkrug->setRect(QRectF(-30,-30,120,80)); pkrug->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
C++ (Qt)#include <QApplication>#include <QGraphicsScene>#include <QGraphicsView>#include <QGraphicsItem> class CircleItem : public QGraphicsItem{public: CircleItem( qreal radius, QGraphicsItem* parent = 0 ) : QGraphicsItem( parent ) , radius_( radius ) {} virtual ~CircleItem() {} void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 ) { painter->drawEllipse( QRectF( -radius_ / 2, -radius_ / 2, radius_, radius_ ) ); } QRectF boundingRect() const { return QRectF( -radius_ / 2, -radius_ / 2, radius_, radius_ ); }public: qreal radius_;}; int main( int argc, char** argv ){ QApplication app( argc, argv ); QGraphicsView gv; QGraphicsScene scene( -150, -150, 300, 300 ); gv.setScene( &scene ); gv.setRenderHint( QPainter::Antialiasing ); for( qreal r = 20; r < 300; r += 10 ) scene.addItem( new CircleItem( r ) ); gv.show(); return app.exec();}
C++ (Qt)scene.setSceneRect( -300, -300, 300, 300 );