qml

How to set initial value of a custom slider in qml?

陌路散爱 提交于 2021-02-08 04:07:46
问题 I am using Qt 5.4.1. I have made a custom slider element to be used in other qml components like so: Slider.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 Item { id: root width: 150 height: 30 property int val: slider.value property int maxVal: slider.maximumValue property int minVal: slider.minimumValue property int step: slider.stepSize Slider { id: slider anchors.margins: 20 stepSize: step maximumValue: maxVal minimumValue: minVal style: customStyle /

How to set initial value of a custom slider in qml?

…衆ロ難τιáo~ 提交于 2021-02-08 04:07:34
问题 I am using Qt 5.4.1. I have made a custom slider element to be used in other qml components like so: Slider.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 Item { id: root width: 150 height: 30 property int val: slider.value property int maxVal: slider.maximumValue property int minVal: slider.minimumValue property int step: slider.stepSize Slider { id: slider anchors.margins: 20 stepSize: step maximumValue: maxVal minimumValue: minVal style: customStyle /

How to set initial value of a custom slider in qml?

时光怂恿深爱的人放手 提交于 2021-02-08 04:06:47
问题 I am using Qt 5.4.1. I have made a custom slider element to be used in other qml components like so: Slider.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 Item { id: root width: 150 height: 30 property int val: slider.value property int maxVal: slider.maximumValue property int minVal: slider.minimumValue property int step: slider.stepSize Slider { id: slider anchors.margins: 20 stepSize: step maximumValue: maxVal minimumValue: minVal style: customStyle /

QT QML how to change only one feature of a, say, button style

大兔子大兔子 提交于 2021-02-08 04:01:12
问题 changing the style of a component, seems to replace all the features of the default style. is there a way to change only one feature? For example, suppose i want a red button; import QtQuick 2.7 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 ApplicationWindow { visible: true width: 640 height: 480 Button { height: 200 width: 200 text: "Press me" style: ButtonStyle { // changes background but also throws away everything else // in standard button style background: Rectangle {

Using a C++ class variable in QML file

◇◆丶佛笑我妖孽 提交于 2021-02-08 03:58:16
问题 How can I use a C++ class variable in QML file in Qt. I want to set a variable based on Q_OS_Android in c++ file and evaluate a condition in QML file. How will this be possible? 回答1: You have to declare the variable as property in your header file and register the class with qml in your main. Here is an example for a class Foo and a variable QString var: class Foo : ... { Q_OBJECT Q_PROPERTY(QString var READ getVar WRITE setVar NOTIFY varChanged) public: Foo(); ~Foo(); QString getVar() const

QML Model data by index

早过忘川 提交于 2021-02-07 20:54:10
问题 I have QAbstractListModel based model... class RecordModel : public QAbstractListModel { ... }; QQmlContext *ctxt = engine.rootContext(); ctxt->setContextProperty("recordModel", &model); // QML recordModel.get(0).name // now work How to get a model data by index and role name? ... Solution : // C++ class RecordModel : public QAbstractListModel { Q_OBJECT Q_ENUMS(Roles) public: // ... Q_INVOKABLE QVariant data(int i, int role) const { return data(index(i, 0), role); } }; // QML recordModel

How to interface QML and Java?

感情迁移 提交于 2021-02-07 20:54:10
问题 If QML is used for GUI and Java for developing API for a linux based device,How to interface QML with Java? 回答1: One approach for cross platform integration is using web service. I would probably expose my Java code as a RESTful web service (See JAX-RS) and invoke it from QML using XMLHttpRequest. It's also worth mentioning Java GUI library such as swing / JavaFX has cross platform capability, so it should still run on Linux (and whichever platform runs Java). You might not need to write QML

QML Model data by index

杀马特。学长 韩版系。学妹 提交于 2021-02-07 20:53:01
问题 I have QAbstractListModel based model... class RecordModel : public QAbstractListModel { ... }; QQmlContext *ctxt = engine.rootContext(); ctxt->setContextProperty("recordModel", &model); // QML recordModel.get(0).name // now work How to get a model data by index and role name? ... Solution : // C++ class RecordModel : public QAbstractListModel { Q_OBJECT Q_ENUMS(Roles) public: // ... Q_INVOKABLE QVariant data(int i, int role) const { return data(index(i, 0), role); } }; // QML recordModel

Using QFileSystemModel with ListView

本秂侑毒 提交于 2021-02-07 19:04:58
问题 I'm trying to create a simple ListView that I can use to browse the file system, using QFileSystem . First, I tried to use code I've found that worked for QDirModel: main.qml: ListView { id: list width: 300 height: 500 model: DelegateModel { model: myFileModel delegate: Text{ id: txt text: fileName MouseArea { anchors.fill: parent onClicked: { //Switch directory when clicked list.model.rootIndex = list.model.modelIndex(index); } } } } main.cpp: int main(int argc, char *argv[]) { QApplication

Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()

时光总嘲笑我的痴心妄想 提交于 2021-02-07 17:29:22
问题 I'm trying to change Image with Pushbutton (GPIO PINs) stored inside a folder using QML with PyQt5 Python Code: from gpiozero import Button from signal import pause from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtQml import * import os, time, sys def btn_pressed(): global r return lambda: r.setProperty("source", "/home/pi/Desktop/example/sample/img/img1.jpg") button1 = Button(20) myApp = QGuiApplication([]) myEngine = QQmlApplicationEngine() directory = os.path.dirname(os