MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    createActions();                    	//创建主窗体的所有动作
    createMenus();                       	//创建主窗体的菜单栏

    scene = new QGraphicsScene;
    scene->setSceneRect(-200,-200,400,400);

    initScene();                         	//初始化场景

    QGraphicsView *view = new QGraphicsView;
    view->setScene(scene);
    view->setMinimumSize(400,400);
    view->show();

    setCentralWidget(view);
    resize(550,450);
    setWindowTitle(tr("Graphics Items"));
}
void GraphicsPlotLegendTest::baseTest()
{
    QGraphicsView view;
    view.setMinimumSize(300, 300);
    QGraphicsScene * scene = new QGraphicsScene();
    view.setScene(scene);
    GraphicsPlotLegend * legend = new GraphicsPlotLegend();
    scene->addItem(legend);
    legend->setRect(QRectF(0, 0, 250, 250));

    Graphics2DGraphItem dataItem;

    dataItem.setTitle(QString("Test title"));
        dataItem.setPen(QColor(Qt::blue));
    legend->addDataItem(&dataItem);
    view.show();
    dataItem.setPen(QColor(Qt::red));


    qApp->exec();
}
Beispiel #3
0
int main(int argc,char* argv[])
{
	QApplication app(argc,argv);
	
	// <1>.creat "Scene" ---GraphicsScene
	QGraphicsScene* scene = new QGraphicsScene();
	scene->setSceneRect( QRectF(-200,-200,400,400) );
    
	// <2>.create "butterfly" here
	butterfly* Butterfly = new butterfly();
	Butterfly->setPos(-100,0);
	scene->addItem(Butterfly);//add item to the "Scene"

	// <3>.create "View" ---GraphicView
	// "QGraphicsView" provides a widget displaying
	// the contents of a QGraphicsScene
	QGraphicsView* view = new QGraphicsView();
	view->setScene(scene);
	view->setMinimumSize(400,400);
	view->show();

	return app.exec();
}