qml

Qt Quick快速入门之qml与C++交互

纵饮孤独 提交于 2020-01-20 20:44:50
  C++中使用qml对象,直接使用findChild获取qml对象,然后调用setProperty方法设置属性,当然必须在加载qml之后才能使用,不然findChild找不到对象,用法如下。 engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject * text_Msg = engine.rootObjects()[0]->findChild<QObject*>("text_Msg"); text_Msg->setProperty("color","red");     qml使用C++对象,这也是Qt中Model/View的实现方法,下面是一个例子。   首先,类需要继承自QObejct class User:public QObject { Q_OBJECT Q_PROPERTY(QString Name READ Name WRITE setName NOTIFY NameChanged) Q_PROPERTY(int Age READ Age WRITE setAge NOTIFY AgeChanged) Q_PROPERTY(QString Message READ Message WRITE setMessage NOTIFY MessageChanged) public: User(); User

QML笔记-2种方式实现心脏跳动

陌路散爱 提交于 2020-01-19 13:54:34
程序运行截图如下: 随着时间,心脏会放大和缩小: 这里大逻辑如下: 把心图片先放大,然后在缩小。 先放大又分为使用Sacle进行放缩,或者使用transform进行放缩 关键代码如下: import QtQuick 2.5 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") color: "black" Image{ id: loveImg source: "qrc:/img/love_PNG89.png" anchors.centerIn: parent // SequentialAnimation{ // running: true // loops: Animation.Infinite // ScaleAnimator{ // target: loveImg // from: 0.2 // to: 1 // duration: 400 // } // ScaleAnimator{ // target: loveImg // from: 1 // to: 0.2 // duration: 400 // } // } transform: Scale{ id: loveTransform property real

懒人发部Qt程序操作

爱⌒轻易说出口 提交于 2020-01-18 01:23:50
背景 在Qt程序发布的过程中感觉诸多繁琐,查询大量文章,找到了一种简单的方法。 原理 同样是使用官方提供的windeployqt这个工具自动复制依赖项。不同的是不用打开命令行窗口操作。直接QtCreator中运行即可。 方法 在QtCreator部署中添加Deploy步骤 Command: windeployqt Arguments: %{buildDir}/%{CurrentBuild:Type}/%{CurrentProject:Name}.exe Working directory: %{buildDir} Ctrl+R运行,在发布目录中已添加了需要的依赖项。 注意 在打包QtQuick程序的依赖项时,windeployqt并没有把qml中使用的模块复制过来。解决方法是在main.cpp文件中添加qml所以用到的对应C++的依赖头文件,例如 #include <QtSql> ,在pro文件中添加Qt+=sql。 引用 参考《发布Qt Widgets桌面应用程序的方法》 来源: CSDN 作者: Jason-Tian 链接: https://blog.csdn.net/oThink1/article/details/104015440

网页版QML

一个人想着一个人 提交于 2020-01-17 23:31:09
在网页上边写QML代码边显示效果。(文末项目地址)   该项目旨在将QML的功能引入到Web浏览器。以下是QML外观示例: 上手体验   边写边看到效果挺不错的,渲染速度还可以,但是只有部分的代码高亮和不支持自动补全代码的功能。支持常用的控件如Rectangle,Item,Text,TextInput等控件,也支持部分Controls 1.0和2.0版本的控件的 部分功能 ,如Button,CheckBox,ComboBox等控件。 项目地址: https://github.com/qmlweb/qmlweb 体验地址: https://qmlweb.github.io/ 更多有趣好玩的项目请关注公众号「Qt君」。 来源: https://www.cnblogs.com/qthub/p/12207751.html

翻译 | QML编码约定

孤者浪人 提交于 2020-01-17 23:28:33
本文翻译自: https://doc.qt.io/qt-5/qml-codingconventions.html 原作者: Qt官网   本文档包含我们在文档和示例中应该遵循的QML编码约定,并建议其他人也遵循。 0x01 QML对象声明   在整个文档和示例中, QML对象属性始终按以下顺序构造 : id property declarations(自定义属性声明) signal declarations(信号声明) JavaScript function(js函数) object properties(对象属性) child object(子对象) states(状态机) transitions(过渡效果)    为了提高可读性,我们用空行将这些不同的部分分开 。 例如,photo的QML对象如下所示: Rectangle { id: photo // 第一行的id使查找对象变得很容易 property bool thumbnail: false // 自定义属性声明 property alias image: photoImage.source signal clicked // 信号声明 function doSomething(x) // js函数 { return x + photoImage.width } color: "gray" // 对象属性 x: 20 //

How to create a tableview(Qt5.12)with model as listModel that can host variable number of columns?

故事扮演 提交于 2020-01-17 16:29:20
问题 I am creating a Table with multiple rows and multiple columns.How can I use Qml TableView to create a table with multiple rows and columns? I tried with an older implementation of tableview but now want to create the same using the new tableview provided in Qt 5.12.Below is the example code of my older implementation QtObject{ id:internals property int rows:0 property int col:0 property int colwidth:0 property var columnName:[] } ListModel{ id: libModel } TableView{ id:tblview height:parent

How to hide an image using transparent rectangle in QML?

妖精的绣舞 提交于 2020-01-17 09:11:41
问题 In the below code I want to hide the image using transparent rectangle. Please give me some solutions. I have used z value but it is not working. The image is still visible. main.qml import QtQuick 2.5 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Image { id:underlyingImage width: 400 height: 400 x:0; y:0; source:"qrc:/Jellyfish.jpg" z:1 } Rectangle { id:hiding_rect width: 400 height: 400 x:0; y:0; color:"transparent" z:100 } } 回答1: You can

QML基础——创建 Qt Quick 项目

╄→尐↘猪︶ㄣ 提交于 2020-01-17 08:57:27
一、创建 Qt Quick 应用程序 1. 选择:文件 -> 新建文件或项目 -> Application -> Qt Quick Application ,选择。 2. 设置项目的名称及其所创建的路径,一般情况下,为了便于管理,项目路径不会频繁的发生变化,建议勾选“设为默认的项目路径”复选框。 3. 对于某些 Qt Quick 应用程序,必须在“Minimal required Qt version”中选择要开发的 Qt 版本。Qt 版本确定在 QML 文件中使用的 Qt Quick 导入。 4. 选择用于运行和构建项目的“kits”,然后单击下一步。 注意: 如果已在“工具 -> 选项 -> 构建和运行 -> 构建套件”中指定了套件,则会列出套件。 5. 查看项目设置,然后单击完成以创建项目。 6. 编译运行 注意: 这里选择的是桌面环境,如果要在移动设备上运行,可以直接使用真机,或者模拟器,这部分内容在后面章节再做分享。 二、创建 Qt Quick UI 项目 选择:文件 -> 新建文件或项目 -> 其他项目 -> Qt Quick UI 或 Qt Quick Controls UI,选择。 在“Minimal required Qt version”字段中选择要开发的 Qt 版本。Qt 版本确定在 QML 文件中使用的 Qt Quick 导入。可以稍后添加导入,以将 Qt

How to use a ListView with custom item QML

北城余情 提交于 2020-01-17 08:30:45
问题 I am a newbie in QML. I made thanks to internet ressources this accordion : Item { default property var contentItem: null property string title: "panel" id: root Layout.fillWidth: true height: 30 Layout.fillHeight: current property bool current: false ColumnLayout { anchors.fill: parent spacing: 0 Rectangle { Drag.active: dragArea.drag.active id: bar Layout.fillWidth: true height: 30 color: root.current ? "#81BEF7" : "#CEECF5" Text { anchors.fill: parent anchors.margins: 10

Q_GADGET vs an accessor object for manipulating a polymorphic tree of C++ objects from QML

喜欢而已 提交于 2020-01-17 06:14:09
问题 I have a polymorphic tree of C++ types that I need to work with from QML. Memory usage and performance are key here, so I wonder which approach would be more efficient: Q_GADGET - without a doubt the easier and faster way to do it. I can directly use properties (without notifications so no bindings either) and slots to access each object's members. It relies on meta data generation and some kind of object identification in the qtquick runtime. Use an global accessor object for accessing