qt-quick

Measuring elapsed time in QML

拥有回忆 提交于 2019-12-05 06:42:50
Let's consider the following example: we have a Qt Quick Controls Button . The user clicks it twice within 5 seconds. After pushing the Button for the first time, the QML Timer is running for these 5 seconds. We want to measure the time elapsed between two clicks, with a millisecond accuracy. Unfortunately, the QML Timer can't show us the elapsed time. As suggested on the BlackBerry forums, it would be possible to compare the dates. This isn't very handy, though, since the first click might occur on 31 Dec 2015, 23:59:55 and the second on 1 Jan 2016, 00:00:05 and the check would have to be

Comparison of two approaches to rendering raw OpenGL into a QML UI in Qt

点点圈 提交于 2019-12-05 06:04:53
According to this article, there are two main methods for rendering raw OpenGL into an application whose UI is otherwise managed by QtQuick's scene graph. In short, they are (according to my understanding): Calling raw OpenGL methods in hand-written code that is hooked into the scene graph's render loop through some APIs exposed by QtQuick. Rendering the raw OpenGL portion of your scene to a QQuickFramebufferObject, which is treated like a component in the scene graph and itself rendered as if it were a texture. What are the advantages/disadvantages of the two approaches? The issue with

FileDialog in QTQuick (QML): Save file under given name

折月煮酒 提交于 2019-12-05 03:30:44
We're building a Qt Quick app, that must be able to save a file under a given name . In the FileDialog component you can only set a directory. This is not very user-friendly, since you don't want to type in a filename by hand every time you download a file. So far we tried different things FileDialog from QtQuick.Dialogs: filename cannot be set Native dialog via QPlatformFileDialogHelper (naughty private c++ hack): filename cannot be set on Linux (Gnome) Native dialog via static QFileDialog::getSaveFileName(): in Quick application there is no QWidget available for 'parent' QT dialog via

How to change the geometry of main window programmatically at run time w.r.t QML?

前提是你 提交于 2019-12-05 00:34:36
问题 I have Qt Creator 2.6.1. I created simple Qt Qucik 2.0 project from project templates and changed main.qml file on this: import QtQuick 2.0 Rectangle { width: 360 height: 360 color: "red" MouseArea { anchors.fill: parent onClicked: parent.height = 180 } } If i will click on rectangle it should be reduced in half. And it is occured, but window is not reduced. What is a best solution, if i want that main window must repeat geometry of main qml rectangle? UPDATE. One solution was found. See Amit

how to integrate qml file into qt-widgets app?

心不动则不痛 提交于 2019-12-04 20:34:03
I have an qt widgets application. I want to add the switch control to my form. I added to my form QDeclarative widget and add this line to the code but nothing shown. ui->declarativeView->setSource(QUrl::fromLocalFile("test.qml")); This is the content of the qml file (I added this file to the resources) It display in qtcreator under resources/[project_name.qrc]/test.qml import QtQuick 2.4 import QtQuick.Controls 1.3 Button{ text:aaaa } I added the pro file : qt += declarative What am i doing wrong?? I'm using Qt 5.4.1 QtCreator 3.3.1. techneaz 1. QDeclarativeView is for older Qt versions. If

How to create and use C++ objects in QML Javascript

五迷三道 提交于 2019-12-04 18:39:21
问题 My app uses both c++ and QML. I've defined several objects in C++ part to access SQL etc. It looks like: class MyObject : public QObject { Q_OBJECT public: MyObject(QObject *parent = 0); Q_INVOKABLE void someFunction(const QString &query); }; qmlRegisterType<MyObject>("xxx.xxx", 1, 0, "MyObject"); Ideally, I need to use these objects only in Javascript not in QML. I tried a lot of examples and read all the documentation but still can't solve my problem. So my questions: How can I instance in

Binding Checkbox 'checked' property with a C++ object Q_PROPERTY

不羁岁月 提交于 2019-12-04 09:53:55
I'm learning QtQuick and I'm playing with data binding between C++ classes and QML properties. In my C++ object Model, I have two properties : Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged) Q_PROPERTY(bool status READ getStatus WRITE setStatus NOTIFY statusChanged) And in my .qml file : TextEdit { placeholderText: "Enter your name" text: user.name } Checkbox { checked: user.status } When I change the user name with setName from my C++ code, it is automatically reflected in the view. When I check/uncheck the checkbox, or when I call setStatus() from my C++ code, nothing

64 bit integers in QML

谁说胖子不能爱 提交于 2019-12-04 06:59:30
How do I deal with 64 bit integers in QML? I know that useless Javascript can't handle them normally as it uses doubles for everything, and if I try to use them in a signal, everything gets set to undefined . Is there a way around this? Perhaps I have to use a QVariant or something? Simon Warta Create your own Integer64 class derived from QObject and give it the functions you need, like class Integer64 : public QObject { Q_OBJECT public: // ... Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) QString value() const; void setValue(QString value); Q_INVOKABLE void add

How to prevent blurry QtGraphicalEffects from being cut off?

时光毁灭记忆、已成空白 提交于 2019-12-04 05:41:00
I'm trying to add effects to my items using QtQuick 2 with QtGraphicalEffects, but I don't quite understand how to tweak really blurry effects to look right. In this case, the drop shadow is poorly sized and is getting clipped at the edges before it entirely fades away. How can I make it blend in nicely and not get cut off? This is the code for the window: import QtQuick 2.0 import QtGraphicalEffects 1.0 Item { width: 250 height: 75 Text { id: textItem x: 10; y: 10 text: "how can I fix my shadow?" } DropShadow { id: shadowEffect anchors.fill: textItem source: textItem radius: 8 samples: 16

How to print(with the printer) a QML object?

强颜欢笑 提交于 2019-12-03 19:38:33
问题 I have designed a sales receipt with Qt Quick and I want to print it with the printer. How can I do this? Here is my main.cpp QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral("qml/Caisse-MBM/main.qml")); viewer.showFullScreen(); 回答1: You can use QQuickView::grabWindow() to get a QImage and then do whatever you want with it, print it, save it... QImage image = view->grabWindow(); Afterwards you can follow this post to get the image to print. 来源: https://stackoverflow.com