- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我通过扩展 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() * y_factor;
qreal width;
qreal height = y_factor;
if (note->getDuration() != 0)
{
width = note->getDuration() * x_factor;
}
else
{
// TODO
width = 500 * x_factor;
}
QRectF noteRectangle = QRectF(left, top, width, height);
node->appendChildNode(new QSGSimpleRectNode(noteRectangle, Qt::black));
}
node->markDirty(QSGNode::DirtyForceUpdate);
return node;
}
最佳答案
来自updatePaintNode
的文档:
The function is called as a result of
QQuickItem::update()
, if the user has set theQQuickItem::ItemHasContents
flag on the item.
您需要做两件事:定期调用 update()
并设置标志。仅此而已。
如果您需要 update()
的报价来源,您需要 QQuickWindow::frameSwapped()
或类似的信号。这会在每一帧发出,并且恰好是每一帧。所以,这会起作用:
QSGNode * myNode = ...;
QObject::connect(window, &QQuickWindow::frameSwapped, [=](){ myNode->update(); });
关于c++ - 定期重绘 QQuickItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19455518/
我有两个 QQuickItem s 并且我想在将它暴露给 QML 之前用 C++ 在另一个之上绘制一个。我想这样做是因为我想要第二个 QQuickItem (从这里开始我将其称为背景 QQuickIt
我目前正在为 Qt Quick 建立一个 C++ 工厂。我需要能够将工厂生成的子项添加到另一个自定义 QQuickItem,如下所示: class Bar : public QQuickItem {
我对这个错误束手无策。任何有关如何追踪它的建议都将不胜感激。 背景: 我一直在尝试将 ogre3d View 实现为 Qt5 中的 QQuickItem。有一个示例 (qmlogre) 表明这是可能的
我通过扩展 QQuickItem 并覆盖 updatePaintNode() 函数创建了一个自定义 QML 元素。 因为我需要沿着实时增长的时间轴绘制矩形,所以我需要为每个新帧重新绘制 GUI。 有没
下面的应用程序输出从一个 QQuickItem 映射的坐标到另一个。根据文档: object mapToItem(Item item, real x, real y) Maps the point (
我想用可拖动的 QQuickItems 编写简单的 Qt Quick 应用程序。由于项目中嵌入了 MouseArea,因此项目可以很好地拖动。但问题是鼠标事件不会在虚拟重载函数中触发到 C++ 代码中
我创建了一个基本的 QML 应用程序,它使用 QQuickView 创建 View ,并在其中包含自定义 QQuickItems。我想通过重新实现 mousepressevent(QEvent *)
我创建了一个 QPixmap 并使用 QPainter 在其上绘制了较小的 QPixmap。我想将图像用作 QQuickItem 的背景。是否有捷径可寻? 最佳答案 如果您的自定义项源自 QQuick
我使用QGraphicsItem工作了很长时间,它有transform()函数。现在我不会对 QQuickItem 做同样的事情,但不幸的是它错过了 transform() 。所以我的问题 - 如何获
我创建了一个 QPixmap 并使用 QPainter 在其上绘制了较小的 QPixmap。我想将图像用作 QQuickItem 的背景。是否有捷径可寻? 最佳答案 如果您的自定义项源自 QQuick
我有一个 C++ 类 Bar,它包含对另一个类 Foo 的实例的引用。当调用 Bar 上的方法时,我想在 Foo 实例上发出 QML 信号。我已经 20 年没有用 C++ 编写代码了,QML 用来发出
我有一个QQuickItem派生类 // Class class MyQQuickItem : public QQuickItem { Q_OBJECT } // updatePaintNode
Qt 文档中有很多关于处理模型和 View 的好资源,例如:http://doc.qt.io/qt-5/model-view-programming.html ,但我似乎找不到任何与 QtQuick
我有一个继承自 QQuickItem 的类,在里面我正在操作它的 width height 属性。我也暴露了我自己的属性。 class MyQQuickItem : public QQuickItem
我想在自定义 QQuickItem 中渲染具有很多点 (>1.000.000) 和不同颜色的绘图。 稍后我想为这些点设置动画(在坐标和颜色之间淡入淡出),所以我认为 QQuickPaintedItem
如何将QQuickItem打印到打印机? QQuickItem = 基本上任何 QML 元素,如文本或矩形,及其子元素 或者:如何将 QQuickItem 转换为位图/QImage 以进行打印? 最佳
我有兴趣通过 C++ QQuickItem 访问 qml 父项的属性。我有一个名为 VisibleTag 的自定义 QQuick 项目,它扩展了 QQuickItem。任何包含此对象标签的 qml 项
有一个 QQuickPaintedItem 带有重载的鼠标事件处理程序: void Plotter::mousePressEvent(QMouseEvent *event) { qDebug(
我在 Qtquick 上使用 OpenGL 绘图,无论我在 QML 上的 OpenGlVideoQtQuick 上放置什么尺寸,它总是占据窗口的整个空间。我希望能够控制它的大小。 我创建了这个使用 O
我想在 QQuickItem 上打开一个 QFileDialog。 void MyCoolQQuickItem::loadFileDialog() { QString filename =
我是一名优秀的程序员,十分优秀!