#include <QtGui>class PieChart : public QLabel{ Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QColor color READ color WRITE setColor)public: PieChart(QLabel *parent = 0); QString name() const; void setName(const QString &name); QColor color() const; void setColor(const QColor &color); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); Q_INVOKABLE void clearChart();signals: void chartCleared();private: QString m_name; QColor m_color;};PieChart::PieChart(QLabel *parent) : QLabel(parent){ // need to disable this flag to draw inside a QDeclarativeItem //setFlag(QGraphicsItem::ItemHasNoContents, false);}QString PieChart::name() const{ return m_name;}void PieChart::setName(const QString &name){ m_name = name;}QColor PieChart::color() const{ return m_color;}void PieChart::setColor(const QColor &color){ m_color = color;}void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){ QPen pen(m_color, 2); painter->setPen(pen); painter->setRenderHints(QPainter::Antialiasing, true); //painter->drawPie(boundingRect(), 90 * 16, 290 * 16);}void PieChart::clearChart(){ setColor(QColor(Qt::transparent)); update(); emit chartCleared();}
#inlcude "moc_<имя файла>.cpp"