开发者

How to add an arc to the foreground of a QGraphicsView

how is it possible to add an QPainter arc to the QGraphicsView foreground. I found QGraphicsView.drawForeground (self, QPainter, QR开发者_开发百科ectF), but I don't understand how to use it. I am new to qt. I also know that it is possible to add an art to the QGraphicsScene, but I need the scene for something else. Or is there an easier way to add an arc over the scene to the QGraphicsView? The arc must be variable. Hope someone can help me.


You will need to create your own subclass of QGraphicsView and implement the drawForeground() method. You can use this code as an example:

MyGraphicsView.h:

#ifndef MYGRAPHICSVIEW_H
#define MYGRAPHICSVIEW_H

#include <QGraphicsView>

class MyGraphicsView : public QGraphicsView
{
public:
    MyGraphicsView(QWidget * parent = 0);
    MyGraphicsView(QGraphicsScene * scene, QWidget * parent = 0);
    virtual ~MyGraphicsView();

protected:
    void drawForeground(QPainter * painter, const QRectF & rect);
};

#endif  /* MYGRAPHICSVIEW_H */

MyGraphicsView.cpp:

#include "MyGraphicsView.h"

MyGraphicsView::MyGraphicsView(QWidget * parent) :
    QGraphicsView(parent)
{
}

MyGraphicsView::MyGraphicsView(QGraphicsScene * scene, QWidget * parent) :
    QGraphicsView(scene, parent)
{
}

MyGraphicsView::~MyGraphicsView()
{
}

void MyGraphicsView::drawForeground(QPainter * painter, const QRectF & rect)
{
    int startAngle = 30 * 16;
    int spanAngle = 120 * 16;
    painter->drawArc(rect, startAngle, spanAngle);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜