qml

QML highest number (float/integer) possible

安稳与你 提交于 2019-12-23 22:57:29
问题 In JavaScript the highest integer possible is defined via Number.MAX_SAFE_INTEGER. and also in C++ can be obtained with the std: std::numeric_limits<int>::max() Is there such a constant in QML for ints or doubles? 回答1: As originally suspected, the 2000000000 number listed in the documentation is incorrect. Also, IMO this is an important value that shouldn't really be subject to such careless approximations. "Around" should only be used when the actual value is unknown for certain or not

QML: Cannot read property 'xxx' of undefined

泄露秘密 提交于 2019-12-23 20:22:12
问题 ApplicationWindow { id: root property string rootName: "--rootName" visible: true width: 800 height: 400 title: qsTr("WatchFace Maker") WatchLcd{ property string watchLcdInApp: "watchLcdInApp" id: watchLcd } TextAdder{ id: textAdder Component.onCompleted: { console.log("APP: ", root.watchLcd.watchLcdInApp)//#Error!!! remove root, it works. } } } I want to know: Why it doesn't work when I add root id in above commented line? How do children component access sibling component's property if

How to manage lifetime of dynamically allocated QObject returned to QML?

回眸只為那壹抹淺笑 提交于 2019-12-23 19:24:56
问题 I have this code: QVariant componentFromCode(QString code) { QQmlComponent * component = new QQmlComponent(engine); engine->setObjectOwnership(component, QQmlEngine::JavaScriptOwnership); connect(component, &QQmlComponent::destroyed, this, &Factory::echo); component->setData(code.toUtf8(), QUrl()); return QVariant::fromValue(component); } But Factory::echo() is never called, which means the object gets leaked every time the function is called. This is what I have on the QML side: onClicked: {

Broken recurssive instantiation checks

雨燕双飞 提交于 2019-12-23 19:14:12
问题 I notice that QML has some unspecified problem with the following - when a delegate tries to instantiate an object that contains it (the delegate that is). Consider this trivial tree builder example: // Object.qml Row { property int c : 0 Rectangle { width: 50 height: 50 color: "red" border.color: "black" MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if (mouse.button === Qt.LeftButton) c++ else if (c) c-- } } } List { model: c } } // List.qml

Bounding box of wrapped text

二次信任 提交于 2019-12-23 18:55:45
问题 I want to draw a rectangle around a QML Text object that is using word wrapping. TextMetrics seems like it would be ideal, but it does not appear to support wrapped text. How can I measure how text is laid out in a Text object? Must I match the wrapping logic and manually calculate the offsets using TextMetrics and FontMetrics? 回答1: You can use contentWidth and contentHeight: Text { text: "..." wrapMode: Text.Wrap Rectangle { border.color: "red" color: "transparent" width: parent.contentWidth

Qml练习:进度圆环绘制

孤街浪徒 提交于 2019-12-23 18:02:41
import QtQuick 2.9 import QtQuick.Window 2.9 Item { id: root width: 400 height: 400 Rectangle { id:rect width: 300 height: width radius: width/2 property int value:30 //取值0-100 antialiasing: true anchors.centerIn: parent color: "gray" Text { id: ratio text: String ( "%1%" ) .arg ( rect.value ) font { pointSize: 30 family: "黑体" } color: "white" anchors.centerIn: parent } Canvas { id:canvas antialiasing: true anchors.fill: parent onPaint: { var ctx = getContext ( "2d" ) //绘图之前清除画布 ctx.clearRect ( 0,0,width,height ) ctx.strokeStyle = "aquamarine" ctx.lineWidth = 12 ctx.beginPath ( ) ctx.arc (

Presence and location of a property in a QML singleton source results in arbitrary bugs

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:59:40
问题 So I was finally able to reproduce it in an MCVE: // S_Settings.qml pragma Singleton import QtQuick 2.7 Item { property real bsize: 50 } // in main() qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/S_Settings.qml")), "Set", 1, 0, "SS"); // main.qml import QtQuick 2.7 import QtQuick.Window 2.2 import Set 1.0 Window { id: main visible: true width: 300 height: 200 Rectangle { anchors.centerIn: parent width: SS.bsize * 4 height: SS.bsize * 2 radius: SS.bsize * .5 color: "red" border.color:

How to provide data from PySide QAbstractItemModel subclass to QML ListView?

懵懂的女人 提交于 2019-12-23 16:53:53
问题 I have an app I'm writing in PySide that has a QML UI. I have subclassed QAbstractListModel in Python: class MyModel(QtCore.QAbstractListModel): def __init__(self, parent=None): QtCore.QAbstractListModel.__init__(self, parent) self._things = ["foo", "bar", "baz"] def rowCount(self, parent=QtCore.QModelIndex()): return len(self._things) def data(self, index, role=QtCore.Qt.DisplayRole): if role == QtCore.Qt.DisplayRole: return self._things[index.row()] return None I provide the model to my QML

qml c++ property bindings with multiple threads

喜欢而已 提交于 2019-12-23 16:08:47
问题 I am creating an modular application. It has a Core , and a few modules, amongs which is a gui module. These modules can be started via the command line: myApp gui=qml=qmlFile.qml connection=serial=/dev/ttyS1 will start the app with one (multiple is also possible) gui and one serial connection. There is always one Router object, which handles the connection. Guis are loaded by a class that looks like this: class Gui :QObject{ Core* core; public: QQmlApplicationEngine engine; public slots: