qquickitem

qml+opencv(一)

对着背影说爱祢 提交于 2020-03-01 21:04:23
前言 突然想起opencv,一直想做人脸识别,可是理论基础太水,只能慢慢来,去年学习了一会,然后公司让我去搞app和网络,就一直搁着,现在学习qml,突然想能不能在qml里面使用opencv,所以就有了这篇文章。 QQuickItem和QObject 在QML中,可视化的基础组件是Item,不可视化的就是QtObject,它们对应C++中的QQuickItem和QObject类,扩展QML组件一个继续基于QML中的Item扩张,还有就是继承QQuickItem,我们想把opencv加到QML中,那么只有继承QQuickItem了。 怎么使用,那还要看QML新的渲染机制,Qt5的QML渲染基于OpenGL,其场景的渲染在单独的线程进行,我们需要需要QQuickItem返回能够描述场景的对象,就是QSGNode。实现QQuick的updatePaintNode函数就OK了,我们在updatePaintNode,描述怎么渲染。 类的关系 OpenCVcapture继承QOjbect,其是图像捕获的基类,OpenCVcamera是OpenCVcapture子类,完成从摄像头捕获数据。OpenCVaction类封装了opencv图像算法操作。OpenCVshowFrame继承QQuickItem,实现可视化。 #include <QApplication> #include

Qt : How to monitor a Q_PROPERTY change on C++ side instead of QML

独自空忆成欢 提交于 2020-02-06 11:28:51
问题 I am using Qt 5.9.3. I have following property declared in my app's main.qml Code: //main.qml MyQuickItem { property color nextColor onNextColorChanged: { console.log("The next color will be: " + nextColor.toString()) } } // MyQuickItem.h class MyQuickItem : public QQuickItem { } Question: How can I make onNextColorChanged be defined in the C++ side? I know that I can also make nextColor as a property inside C++ class MyQuickItem . like so // MyQuickItem.h class MyQuickItem : public

Qt : How to monitor a Q_PROPERTY change on C++ side instead of QML

随声附和 提交于 2020-02-06 11:27:19
问题 I am using Qt 5.9.3. I have following property declared in my app's main.qml Code: //main.qml MyQuickItem { property color nextColor onNextColorChanged: { console.log("The next color will be: " + nextColor.toString()) } } // MyQuickItem.h class MyQuickItem : public QQuickItem { } Question: How can I make onNextColorChanged be defined in the C++ side? I know that I can also make nextColor as a property inside C++ class MyQuickItem . like so // MyQuickItem.h class MyQuickItem : public

How to make a resizable rectangle in QML?

我与影子孤独终老i 提交于 2019-12-28 12:08:07
问题 I'm looking for a simple way to create a rectangle in a QQuickItem . I want to resize, and drag the borders of this rectangle like this (found at resizable QRubberBand) Has someone an idea? 回答1: There are probably several ways to achieve the desired result. Since I've considered the implementation of a similar Component for a cropping tool software of mine, I'm going to share a toy example which uses part of that code. Differently from the rubber band in the example, my Rectangle is resizable

How can I get access to object of `QQmlApplicationEngine` inside a `QQuickItem` derived class?

妖精的绣舞 提交于 2019-12-24 19:19:30
问题 The variable engine in the following typical main function of a QtApp is a valid instance of QQmlApplicationEngine . int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); return app.exec(); } Is it possible to get access to object of QQmlApplicationEngine inside a function of a QQuickItem derived class? If yes, how? class TestItem : public QQuickItem { public: TestItem(); SomeMethod() { // Is

How to create a new QQuickItem copy from scratch on C++ side with the same properties as an existing one

跟風遠走 提交于 2019-12-24 18:29:17
问题 I have a QQuickItem fetched from C++ side like this. QQuickItem * my_item = qmlEngine->rootObjects()[0]->findChild<QQuickItem*>("ItemObjectName"); my_item is valid & has all the properties set on to it. Scenario I have 2 windows which need this QQuickItem to be drawn on alterantively. I want to render this my_item to a different window. This works perfectly fine as long as I set the Parent of the my_item to the other window // the_other_window is a QQuickWindow QQuickWindow * the_other_window

How to map a saved texture directly on a QuickItem & display it?

安稳与你 提交于 2019-12-24 08:08:59
问题 In my Qt app with C++ , I am using a QQuickItem derived class to display textures which are produced on every frame render by running some filters on each frame render. this works fine. Next, I used the takeTexture method provided by QOpenGLFramebufferObject to save some textures & display them back whenever required. These saved textures are of type GLuint s. I am able to display it back using the normal OpenGL rendering pipeline. It works well. But, Is there a way I can avoid the rendering

How to set a pure C++ object instance in a QQuickItem [duplicate]

只愿长相守 提交于 2019-12-13 09:01:20
问题 This question already has answers here : How to get a valid instance of a QQuickItem on C++ side (2 answers) Closed 3 years ago . I have QtApp & a pure C++ library. The C++ library exposes a one simple class called MyCppLibApiClass . The QtApp has a class which is embedded on main.qml . Following is the class: class MyQuickItem : public QQuickItem { MyQuickItem(); } Following the qml code for the quick item : import MyQuickItem 1.0 MyQuickItem { id: myQuickItemID visible: true objectName:

How create a separate copy of a QQuickItem & render it on a different window

你离开我真会死。 提交于 2019-12-12 04:48:11
问题 I have a QQuickItem fetched from C++ side like this. QQuickItem * my_item = qmlEngine->rootObjects()[0]->findChild<QQuickItem*>("ItemObjectName"); my_item is valid & has all the properties set on to it. Scenario I have 2 windows which need this QQuickItem to be drawn on alterantively. I want to render this my_item to a different window. This works perfectly fine as long as I set the Parent of the my_item to the other window // the_other_window is a QQuickWindow QQuickWindow * the_other_window

Clip children of custom qml item after custom shape

…衆ロ難τιáo~ 提交于 2019-12-11 07:15:04
问题 I have a custom QQuickItem which I created and I wanted to create a rounded cornered window. So I implemented a QQuickPaintedItem and exported to QML . The problem is that the item's children are expanding by the item's bounding rectangle, which is a rectangle and not a rounded rectangle like I want it. Here's how it looks: Here is my code: main.qml import QtQuick 2.7 import QtQuick.Window 2.2 import mycustomlib 1.0 Window { id: wnd width: 300 height: 280 visible: true flags: Qt