We can also use various other property types. QML has built-in support for the types listed in the QML Basic Types documentation, which includes the following:
- bool, unsigned int, int, float, double, qreal
- QString, QUrl, QColor
- QDate, QTime, QDateTime
- QPoint, QPointF, QSize, QSizeF, QRect, QRectF
- QVariant
If we want to create a property whose type is not supported by QML by default, we need to register the type with QML.
要点:
改为PieSlice 画图,PieChart不可视。
Like PieChart, this new PieSlice type inherits from QDeclarativeItem and declares its properties with Q_PROPERTY():
Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice)
//![0]
void PieChart::setPieSlice(PieSlice *pieSlice)
{
m_pieSlice = pieSlice;
pieSlice->setParentItem(this);
}
//![0]