小编use*_*244的帖子

定期重绘QQuickItem

我通过扩展QQuickItem并覆盖updatePaintNode()函数创建了一个自定义QML元素.

由于我需要沿着将实时增长的时间线绘制矩形,我需要为每个新帧重绘GUI.

有没有办法让每个新帧定期执行updatePaintNode()函数?

我试过调用node->markDirty(QSGNode::DirtyForceUpdate)哪个不会导致定期调用updatePaintNode()函数.

编辑:这是我的代码:

QSGNode *PianoRoll::updatePaintNode(QSGNode *n, QQuickItem::UpdatePaintNodeData *data)
{
    QSGGeometryNode *node = static_cast<QSGGeometryNode *>(n);
    if (!node)
    {
        node = new QSGSimpleRectNode(boundingRect(), Qt::white);
    }

    node->removeAllChildNodes();

    qreal msPerScreen = 10000;
    qreal pitchesPerScreen = 128;
    qreal x_factor = (qreal) boundingRect().width() / msPerScreen;
    qreal y_factor = (qreal) boundingRect().height() / pitchesPerScreen;

    for (unsigned int i = 0; i < m_stream->notes.size(); i++)
    {
        shared_ptr<Note> note = m_stream->notes.at(i);
        qreal left = boundingRect().left() + note->getTime() * x_factor;
        qreal top = boundingRect().top() + note->getPitch() * …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml

5
推荐指数
1
解决办法
5964
查看次数

标签 统计

c++ ×1

qml ×1

qt ×1