Reputation: 3388
I knew QWidget uses the QPaintEngine class to draw on screen,which QPaintEngine then implemented by various paint engine on corresponding window system or painting framework.So,how QGraphicsItem and Rectangle(in QML) do the painting work in Qt?They also used QPaintEngine?Then what's the relationship in them?
Upvotes: 1
Views: 1132
Reputation: 9986
Each QML element is a QDeclarativeItem, which is in turn a QGraphicsObject which inherits from both QObject and QGraphicsItem, which is the base class for items placed in a QGraphicsScene.
QML objects are also placed in a QDeclarativeView, which is a QGraphicsView. So those are simply C++ QGraphicsItems placed in a QGraphicsScene. They use therefore the QPainter like anything else. This is quite clear when looking at the source code of the Rectangle QML component, which is implemented in the QDeclarativeRectangle class. Look at the QDeclarativeRectangle::paint() and the QDeclarativeRectangle::drawRect(QPainter &p).
You can therefore use the paint engines provided by Qt to render any of those items or reimplement your own paint engine to use accelerated hardware.
Upvotes: 2