简体   繁体   中英

How to render QQuickItem children?

Suppose I have this class:

class CustomRow : public QQuickPaintedItem {
    Q_OBJECT

    CustomRow(QQuickItem* parent) {...}
    void paint(QPainter* painter) {
        /* Custom painting of children here */
    }
}

How could I position and paint the children in a cusom way? For instance, if I had a percentLeft property, how could I make it so that two children are rendered so that the left takes up percentLeft of the space there? Suppose it was in QML like this:

CustomRow {
    percentLeft: 80
    Text {
        text: "Hi"
    }
    Text {
        text: "Bye"
    }
}

How would I make it so that the text that says "Hi" took up 80% of the width of the CustomRow item? Do I just need to position the children and they take care of it themselves?

Do I just need to position the children and they take care of it themselves?

Nailed it. Items are responsible for their own painting. You need not concern yourself with that, only with any custom painting that you do.

You can use property bindings to position the children inside the parent item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM