最近在研究QOPengl QGraphicsView QGraphicsItemQGraphicsScene不过也只是皮毛,也不是做什么技术贴,就是记录一下自己在其中遇到的问题,和自己新学到的东西。

有兴趣的可以交流


目前主要就是利用QGraphicsView 的分层显示,scene的可以容纳数以万计的item


我的理解scene是一个可以存各种item的容器


View就是将这个容器中的内容让用户可见


在绘制任意图形的时候,我遇到了QpainterPath类

其中QPainterPath中有一个参数是需要QPolygonF类

具体代码如下:


QPainterPathpath;
QPolygonFpolygon;
polygon<<QPointF(10,20)<<QPointF(30,20)<<QPointF(20,0)<<QPointF(10,20);
path.addPolygon(polygon);
QGraphicsItem*item_My=scene->addPath(path,QPen(QColor(0,255,0),3,Qt::SolidLine,Qt::FlatCap,Qt::MiterJoin),QBrush(QColor(0,255,0)));
item_My->setFlag(QGraphicsItem::ItemIsSelectable,true);
item_My->setFlag(QGraphicsItem::ItemIsMovable,true);
item_My->moveBy(x,y);








其中,item_My->setFlag(QGraphicsItem::ItemIsSelectable,true);

    item_My->setFlag(QGraphicsItem::ItemIsMovable,true);

这两行代码是比较重要的,QGraphicsItem默认是将鼠标事件关闭的,

这两行代码使Item可以拖拽,可是选择。




在QGraphicsView的最底层,添加了继承QGLwidget类的opengl绘制函数

出现问题是QGraphicsView无法时时刷新界面

对饮解决办法就是


调用QGraphicsView的Viewport的update函数


如果使用Opengl的update函数是不可以的


目前就这么多了


下面是拍的几张图初探 Qt Opengl【2】_技术初探 Qt Opengl【2】_余晖_02初探 Qt Opengl【2】_Qt_03