qml

Using c++ enum in QML as string

不问归期 提交于 2019-12-21 04:57:19
问题 What I would like to do is use the below enum in c++: class MyClass : public QQuickItem { Q_OBJECT Q_PROPERTY(MyEnum enumValue READ getEnumValue) public: enum MyEnum{ MyEnumElement = 0 }; Q_ENUM(MyEnum) slots: MyEnum getEnumValue(){ return enumValue; } private: MyEnum enumValue = MyEnumElement; }; In such a way in QML: MyClass { id: myClass } Text { text: "enumValue is: " + myClass.enumValue } That would result in enumValue is MyEnumElement instead of enumValue is 0 which is the case now. The

how to sort QML TableView in QtQuick 2?

£可爱£侵袭症+ 提交于 2019-12-21 03:01:20
问题 I want to implement a sortable TableView with custom roles with Qt 5.1. But I don't know what to do more to make it sorted when user clicked on header. in my Qt .pro file, I added: !android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets in main.cpp, I used QtWidgets/QApplication as global app instance, and used qmlRegisterType for my new model class(see below): qmlRegisterType<PositionModel>("MyDataModule", 1, 0, "PositionModel"); PositionModel is declared following: class

Performance: QML window repaints himself very slow

两盒软妹~` 提交于 2019-12-21 02:37:47
问题 I've created this QML window but when I grab it's border with a mouse and resize it contents of window are repainted very slow. You can clone my repo and test it yourself. Any ideas how to improve performance? import QtQuick 2.0 Rectangle { id: root width: 600 height: 600 color: "lightgrey" ListView { model: mainModel spacing: 5 width: parent.width orientation: ListView.Horizontal delegate: Rectangle { //width: parent.desiredWidth / mainModel.dataLen()//+ " " + model.sort width: root.width /

Performance: QML window repaints himself very slow

本小妞迷上赌 提交于 2019-12-21 02:37:07
问题 I've created this QML window but when I grab it's border with a mouse and resize it contents of window are repainted very slow. You can clone my repo and test it yourself. Any ideas how to improve performance? import QtQuick 2.0 Rectangle { id: root width: 600 height: 600 color: "lightgrey" ListView { model: mainModel spacing: 5 width: parent.width orientation: ListView.Horizontal delegate: Rectangle { //width: parent.desiredWidth / mainModel.dataLen()//+ " " + model.sort width: root.width /

Qt5 & QtQuick2 - transparent main window

♀尐吖头ヾ 提交于 2019-12-20 20:42:09
问题 I am trying to create a simple Qt UI with a frameless window and rounded corners. Starting from a new project with the QtQuick 2 Application template, my code looks like this: main.cpp #include <QtGui/QGuiApplication> #include "qtquick2applicationviewer.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral("qml/qtquick-test/main.qml")); viewer.setFlags(Qt::FramelessWindowHint); viewer.showExpanded();

How to access the QML object inside the Loader's sourceComponent?

≯℡__Kan透↙ 提交于 2019-12-20 20:29:32
问题 I may need to read or write to some of the properties of the Loader 's sourceComponent from some outside function. What is the way to access the property x of the object inside this Loader 's sourceComponent ? import QtQuick 2.0 Item { width: 200; height: 200 Loader { anchors.fill: parent sourceComponent: rect } Component { id: rect Rectangle { width: 50 height: 50 color: "red" property int x } } } 回答1: When you need to expose an inner object/property to the outside, you should create an

Pass Java Script function as parameter to C++ function

僤鯓⒐⒋嵵緔 提交于 2019-12-20 19:43:29
问题 I declare my object in C++ class Action : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name) public: Action(): QObject(0) {} QString name() const { return "rem"; } Q_INVOKABLE void getData() {}; } and make it available to qml: engine()->rootContext()->setContextProperty("action", new Action()); How to pass to getData() method javascript function as parameter and call this function on C++ side? So from QML point of view it should looks like: action.getData(function(data) { alert(data

Pass Java Script function as parameter to C++ function

左心房为你撑大大i 提交于 2019-12-20 19:43:23
问题 I declare my object in C++ class Action : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name) public: Action(): QObject(0) {} QString name() const { return "rem"; } Q_INVOKABLE void getData() {}; } and make it available to qml: engine()->rootContext()->setContextProperty("action", new Action()); How to pass to getData() method javascript function as parameter and call this function on C++ side? So from QML point of view it should looks like: action.getData(function(data) { alert(data

Qt5 Syntax Highlighting in QML

佐手、 提交于 2019-12-20 11:49:50
问题 I am working on a QtQuick 2.0 presentation and I would like to embed some code samples. is it possible easily to create a syntax highlighting qml element. Can you give me example technologies and ideas on how to achieve it. Thanks 回答1: Qt Quick's TextEdit item exposes a textDocument property, of type QQuickTextDocument . This is explicitly exposed so you can use QSyntaxHighlighter directly with the document. QtQuick textEdit documentation for Qt 5.3 回答2: There is no obvious way to achieve

Unable to make qmlRegisterType work

眉间皱痕 提交于 2019-12-20 10:55:08
问题 I've found some examples of qmlRegisterType on the internet but just can't make it work. I create a new Qt Quick 2 project and add the following contents: This is my .pro file: #Add more folders to ship with the application, here folder_01.source = qml/testlib folder_01.target = qml DEPLOYMENTFOLDERS = folder_01 #Libraries QT += core gui widgets #Additional import path used to resolve QML modules in Creator's code model QML_IMPORT_PATH = #Header files HEADERS += main.hpp #The .cpp file which