qml

Create Model for QML TreeView

左心房为你撑大大i 提交于 2020-01-14 04:37:09
问题 I'm trying to use QML TreeView Model. The example from Qt doesn't include how to create the model. I read this post and tried to use the code from @Tarod but the result is not what I expected. main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> #include "animalmodel.h" #include <qqmlcontext.h> #include <qqml.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); AnimalModel model; model.addAnimal("wolf", "Medium"); model.addAnimal("Bear", "Large");

qml调用c++

强颜欢笑 提交于 2020-01-14 03:37:01
一、将c++对象注册到qml引擎中: 方法有很多种,这里只介绍下面这几种: 1.将c++类型导出为qml可以使用的类型 #include <QtQml> #include <QQmlApplicationEngine> ... ... //注册一定要放在qml上下文之前 //qmlRegisterType<对象名>("自定义的包名",主版本号,次版本号,"qml中的对象名"); qmlRegisterType<MyListModoule>("an.qt.ListModoule",1,0,"MyMoDoule"); ... 2.将c++中创建的对象作为属性传递到qml中 #include <QQmlApplicationEngine> #include <QQmlContext> ... QQmlApplicationEngine engine; //必须在load之前调用,new出来的对象还需要c++这边释放 engine.rootContex()->setContextProperty("test_qml",new Test); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); ... 在qml中使用是,不需要像第一种方法 import,也不需要定义,可直接使用test_qml,类似于一种在qml中的单例对象。 二、c+

My OpenGL QQuickItem won't have the size I want

主宰稳场 提交于 2020-01-14 03:14:15
问题 I'm drawing with OpenGL on Qtquick and no matter what size I put on my OpenGlVideoQtQuick on QML, it always occupies the entire space of the window. I want to be able to control its size. I created this minimal example which draws a green screen with OpenGL. I should be able to control the size of QQuickItem and thus control the size of the green screen to occupy, for example, 1/4 of the screen. You can see that I even tried (and commented) the setWidth and setHeight methods on the QQuickItem

Two-dimensional table with nested scrolling areas in QML

我只是一个虾纸丫 提交于 2020-01-14 03:09:09
问题 I want to create, in QML, a TV-schedule where the vertical axis is a list of Channels and the horizontal axis is time-based. For example something like (source: zappware.com) Initially, I created a vertical ListView with model = the list of Channels delegate = a horizontal ListView every horizontal ListView has model = the list of Events delegate = an Item where the width is proportional to the duration of the Event So far so good. Only drawback is that the horizontal ListViews scroll one by

初识Qt

﹥>﹥吖頭↗ 提交于 2020-01-12 21:12:23
初识Qt 本人硬件工程师一枚,在我开始想通过软件将公司的硬件电路设计标准化之前,我对Qt并不怎么了解,只知道她基于C++语言开发应用程序,然而我的C++也很烂,这也是我不去碰MFC框架而转战Qt的原因之一,当然这两者之间的优缺点对比不再细说;Google了一下Qt了解到的信息如下: Qt发展史 1991年Qt由Trolltech(奇趣科技公司)开发 2008年Nokia(诺基亚)收购了Trolltech,Qt自然成为诺基亚旗下编程语言 2012年Nokia将Qt业务及相关软件技术出售给了Digia(芬兰一家软件公司) 2013年之后,Digia成立了Qt开发团队细心培育Qt,2019年12月11日15点49分Digia发布Qt最新版本为 Qt5.14.0 Qt能做什么 Qt是一个跨平台的C++应用程序开发框架,用她可以轻易做出艺术级的图形界面;Qt 支持跨平台体现在她可以支持各大主流操作系统(Windows、Linux、Unix、嵌入式系统等);总的来说Qt用在各类桌面应用程序开发以及嵌入书系统应用程序开发上,比较典型的 案例 如Linux桌面环境KDE、WPS Office办公软件以及谷歌地图等 Qt商业版和开源版 Qt发行的版本分为Qt商业版和Qt开源版:商业版专门提供给商业软件开发使用,在商业有效期内会提供免费升级和相关技术支持服务;开源版开放Qt源码

What is the difference between Row and RowLayout?

情到浓时终转凉″ 提交于 2020-01-12 06:58:11
问题 This works as intended with Row , but not with RowLayout . Why? What is the difference between the two? ApplicationWindow { title: "Testing" width: 640 height: 480 //RowLayout { Row { anchors.fill: parent Rectangle { id: rect1 width: parent.width * 0.3 height: parent.height color: "blue" } Rectangle { height: parent.height width: parent.width * 0.7 color: "red" } } } 回答1: Row is a Item Positioner. Positioner items are container items that manage the positions of items in a declarative user

How to access a nested QML object from C++?

 ̄綄美尐妖づ 提交于 2020-01-12 06:54:28
问题 Here is a reproducible example: main.qml import QtQuick 2.0 Item { id : root width: 360 height: 360 Text { id : t1 text: qsTr("Hello World") property int someNumber: 1000 anchors.centerIn: parent } MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } } main.cpp #include <QtGui/QGuiApplication> #include <QQmlEngine> #include <QQmlComponent> #include <QQmlProperty> #include <QDebug> #include "qtquick2applicationviewer.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv)

How to access ListView's current item from qml

狂风中的少年 提交于 2020-01-12 03:53:45
问题 I have an application that stores and edits notes. The list of notes is displayed in a listview like this: Page { id: noteList title: i18n.tr("QNote") visible: false Column { anchors.fill: parent ListView { anchors.fill: parent model: notes delegate: ListItem.Standard { text: Title onClicked: editNote(NoteText, Title, modelData); progression: true } } } } function editNote(text, title, item) { pageStack.push(noteEdit, {title: title, text: text}); handler.setActiveItem(item); } The notes item

How to specify wildcards in .qrc resource file of QML?

落爺英雄遲暮 提交于 2020-01-11 05:48:05
问题 There are x number of .png files in a directory. Instead of adding all these manually I would want to specify the directory path in the .qrc file and let it include all of them on its own. What is the way to achieve this? 回答1: No, this is not yet possible, see this bugreport for details. 回答2: Here is a little bash script that generate a qrc file from the content of a folder #!/bin/sh QRC=./resourcefilename.qrc echo '<!DOCTYPE RCC>' > $QRC echo '<RCC version="1.0">' >> $QRC echo ' <qresource>'

QML Screen Coordinates of Component

自作多情 提交于 2020-01-11 05:31:07
问题 If I have a simple, self-contained QML application, I can get the absolute screen coordinates of a component by saying Component.onCompeted: { var l = myThing.mapToItem(null, 0, 0) console.log("X: " + l.x + " y: " + l.y) } where myThing is the id of any other component in the file. However, if this file gets incorporated into another QML file and the component it defines is reused, I don't get the screen coordinates anymore; I get the local coordinates relative to the component where the