qt-quick

Share color values and other read-only values across multiple QML files

别等时光非礼了梦想. 提交于 2019-12-02 13:45:03
问题 I'm looking for a simple way to share read-only values across multiple QML files, for instance; lets say I have a label element: Label { id: titleLabel text: listView.currentItem ? listView.currentItem.text : "IDEAL Networks" font.pixelSize: 20 elide: Label.ElideRight horizontalAlignment: Qt.AlignLeft verticalAlignment: Qt.AlignVCenter Layout.fillWidth: true color: red; padding: { left: 14 } } The color and padding values need to be used in other QML files and other areas of the same file.

QML - Share color values and other read-only values across multiple QML files

若如初见. 提交于 2019-12-02 04:35:40
I'm looking for a simple way to share read-only values across multiple QML files, for instance; lets say I have a label element: Label { id: titleLabel text: listView.currentItem ? listView.currentItem.text : "IDEAL Networks" font.pixelSize: 20 elide: Label.ElideRight horizontalAlignment: Qt.AlignLeft verticalAlignment: Qt.AlignVCenter Layout.fillWidth: true color: red; padding: { left: 14 } } The color and padding values need to be used in other QML files and other areas of the same file. Rather than re-typing red and 14 in multiple locations is there a way I can create a shared library

Wrong coordinates white getting real position of item relative to its parent

送分小仙女□ 提交于 2019-12-01 18:53:24
问题 I have simple scene with only 2 Rectangles . The difference is that first one uses absolute coordinates and second one uses anchors . In this case both of rectangles are placed on the same place. But I get different coordinates at all. import QtQuick 2.4 import QtQuick.Window 2.2 Window { visible: true width: 600 height: 600 Rectangle { id: rec1 x: 200 y: 200 width: 200 height: 200 color: "green" opacity: 0.5 Component.onCompleted: console.log("rec1: " + rec1.x + "," + rec1.y); } Rectangle {

Wrong coordinates white getting real position of item relative to its parent

喜欢而已 提交于 2019-12-01 18:39:41
I have simple scene with only 2 Rectangles . The difference is that first one uses absolute coordinates and second one uses anchors . In this case both of rectangles are placed on the same place. But I get different coordinates at all. import QtQuick 2.4 import QtQuick.Window 2.2 Window { visible: true width: 600 height: 600 Rectangle { id: rec1 x: 200 y: 200 width: 200 height: 200 color: "green" opacity: 0.5 Component.onCompleted: console.log("rec1: " + rec1.x + "," + rec1.y); } Rectangle { id: rec2 anchors.centerIn: parent width: 200 height: 200 color: "blue" opacity: 0.5 Component

ReferenceError in qt quick controls tabview

半腔热情 提交于 2019-12-01 12:27:40
I have written a QT Quick program use TabView. When I click the botton b1 which is in Tabview, the program should call show_text() and print the text of b1, but it print "ReferenceError: b1 is not defined". Any suggestion will be appreciated, thanks. import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Window 2.1 ApplicationWindow { function show_text() { console.log(b1.text) } TabView { id: tv Tab { id: tab1 Button{ id: b1 text:"b1's text" onClicked: { //console.log(b1.text) show_text() } } } } } Pass the object as a parameter import QtQuick 2.2 import QtQuick.Controls 1.1 import

Qt - How to run a C++ function when QML button is clicked? Using QQmlApplicationEngine

旧巷老猫 提交于 2019-12-01 10:57:55
myclass.h #ifndef MYCLASS_H #define MYCLASS_H #include <QDebug> #include <QObject> class MyClass : public QObject { public: MyClass(); public slots: void buttonClicked(); void buttonClicked(QString &in); }; #endif // MYCLASS_H myclass.cpp #include "myclass.h" MyClass::MyClass() { } void MyClass::buttonClicked() { // Do Something } void MyClass::buttonClicked(QString &in) { qDebug() << in; } main.cpp #include <QApplication> #include <QQmlApplicationEngine> #include <myclass.h> #include <QQmlContext> int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine;

QML Screen Coordinates of Component

独自空忆成欢 提交于 2019-12-01 05:55:07
If I have a simple, self-contained QML application, I can get the absolute screen coordinates of a component by saying Component.onCompeted: { var l = myThing.mapToItem(null, 0, 0) console.log("X: " + l.x + " y: " + l.y) } where myThing is the id of any other component in the file. However, if this file gets incorporated into another QML file and the component it defines is reused, I don't get the screen coordinates anymore; I get the local coordinates relative to the component where the statements above are executed. How can I get the absolute screen coordinates of items? Component

QML Drag and Drop (free positioning)

﹥>﹥吖頭↗ 提交于 2019-11-30 14:28:09
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 drag an element in, such an element should stay at the position I've dropped it, e.g. x: 25 and y: 65 .

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

余生颓废 提交于 2019-11-30 10:20:35
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(); dtech 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/questions/16792634/how-to-printwith-the-printer-a-qml-object

How to create grouped/nested properties?

给你一囗甜甜゛ 提交于 2019-11-30 09:49:17
I am trying to do nested properties like 'font.family' or 'anchors.fill', but I cannot initialize them in normal way because it prints 'Cannot assign to non-existent property'. Instead I am forced to use Component.onCompleted method. What's wrong? MyButtonStyling.qml: import QtQml 2.1 QtObject { property QtObject background: QtObject { property color pressed: "#CCCCCC" property color enabled: "#666666" property color disabled: "#555555" } } main.qml: import QtQuick 2.0 Item { width: 400 height: 300 MyButton { text: "TEST" styling: MyButtonStyling { //background.enabled: "#1B2E0A" //Cannot