qt-quick

How to implement QML ListModel like get method for an QAbstractListModel derived model

安稳与你 提交于 2019-11-30 02:13:26
I want to use an QAbstractListModel derived model in QML. Binding the model to views already works great. The next thing I want achieve is the ability to access specific items and their role like it is possible with a QML ListModel grid.model.get(index).DisplayRole But I have no idea how to implement this get method in my QAbstractListModel derived model. Any hints? You can add an Q_INVOKABLE function to the QAbstractItemModel derived class like this: ... Q_INVOKABLE QVariantMap get(int row); ... QVariantMap get(int row) { QHash<int,QByteArray> names = roleNames(); QHashIterator<int,

How to make a transparent window with Qt Quick?

此生再无相见时 提交于 2019-11-30 00:10:00
Is there a way to make the window of a qml application transparent? I'm looking for a detailed description on how to draw simple shapes with qml while making the window of the application transparent, as well as the background. A working source code demo would be awesome. Here is a simple example: main.cpp : #include <QtGui/QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } mainwindow.h : #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QDeclarativeView> class MainWindow : public QDeclarativeView {

QML Drag and Drop (free positioning)

房东的猫 提交于 2019-11-29 19:24:32
问题 There are a lot of QML Drag and Drop Examples out there, but none of them really helps me, because in all the examples you can drag an element into another, where it is centered and all other elements you drag above are laying over it. Is there a way to have some elements on one side and on the other side a big Rectangle where you can drag them in, drop them anywhere inside of it and they stay on their exact drop position? For example, if I got a Rectangle with width: 200; height: 200 and I

Qml timer not triggered in the right interval

谁说我不能喝 提交于 2019-11-29 13:41:58
I've created a timer QML app, and I'm using Timer qml component. The interval is set to 1000 milliseconds (the default one)... but it seems to be working properly only when the app is with focus on it. When I put it in background it seems that it's not triggered every time, and because of that I got some mistakes in the app. I've tried to find anything related to that in the documentation, but I couldn't The timer code is really simple: Timer { id: timer repeat: true onTriggered: {msRemaining -= 1000; Core.secondsToText(type);} } Anyone has any idea about that and how to fix it? Versions: Qt 5

How to apply opacity mask to a QML item?

丶灬走出姿态 提交于 2019-11-29 11:21:38
The look and feel I'm trying to go for is to have a solid color button, and text on it like "Hello World" where the text is completely transparent, and the background shows through the button. In other words, having text as a transparency mask on a button element. Here is one way to do it: // TB.qml MouseArea { width: txt.contentWidth + 20 height: txt.contentHeight + 10 property alias text: txt.text property alias color: sh.color ShaderEffect { id: sh anchors.fill: parent property color color: "red" property var source : ShaderEffectSource { sourceRect: Qt.rect(0, 0, sh.width, sh.height)

How to implement QML ListModel like get method for an QAbstractListModel derived model

寵の児 提交于 2019-11-28 23:13:10
问题 I want to use an QAbstractListModel derived model in QML. Binding the model to views already works great. The next thing I want achieve is the ability to access specific items and their role like it is possible with a QML ListModel grid.model.get(index).DisplayRole But I have no idea how to implement this get method in my QAbstractListModel derived model. Any hints? 回答1: You can add an Q_INVOKABLE function to the QAbstractItemModel derived class like this: ... Q_INVOKABLE QVariantMap get(int

How to make a transparent window with Qt Quick?

纵然是瞬间 提交于 2019-11-28 21:10:37
问题 Is there a way to make the window of a qml application transparent? I'm looking for a detailed description on how to draw simple shapes with qml while making the window of the application transparent, as well as the background. A working source code demo would be awesome. 回答1: Here is a simple example: main.cpp : #include <QtGui/QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } mainwindow.h : #ifndef

Qt Transform matrix

核能气质少年 提交于 2019-11-28 11:17:51
I need to manipulate QML items through QMatrix4x4, in order to apply some perspective transformations. Basically, I defined the class Transform to use an object QMatrix4x4 as argument for the transform field of the QML Item class Transform : public QQuickTransform{ Q_OBJECT Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY matrixChanged) public: explicit Transform(QQuickItem *parent = 0); QMatrix4x4 matrix() const; void setMatrix(QMatrix4x4 matrix); virtual void applyTo(QMatrix4x4 *matrix) const; signals: void matrixChanged(); private: QMatrix4x4 m_matrix; }; where void Transform

Qml timer not triggered in the right interval

爷,独闯天下 提交于 2019-11-28 08:02:35
问题 I've created a timer QML app, and I'm using Timer qml component. The interval is set to 1000 milliseconds (the default one)... but it seems to be working properly only when the app is with focus on it. When I put it in background it seems that it's not triggered every time, and because of that I got some mistakes in the app. I've tried to find anything related to that in the documentation, but I couldn't The timer code is really simple: Timer { id: timer repeat: true onTriggered: {msRemaining

How create shared library in QT/QML

雨燕双飞 提交于 2019-11-28 05:55:31
问题 I have 4 qml files and one main.cpp to load qml file. Is it possible for me to create 1 dll file for those 4 qml file. And use it in different application if so how to do that. 回答1: As already said, there is no need for embedding qml files only in a library. But of course you have the right to do all you want, even that. I know at least 2 ways to do that: 1. Create binary resource file Prepare resource file containing qml files and then compile it: rcc -binary plugin.qrc -o plugin.rcc Now you