diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-10-12 01:08:50 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2013-10-12 01:08:50 +0000 |
commit | c36f2087de4f47f5f6e473a49b78df63e9cd2106 (patch) | |
tree | b348769fa6a5af8a08dbc1b6c7e1902d4684b3c4 | |
parent | button and textfield in qml (diff) | |
download | gpg4usb-c36f2087de4f47f5f6e473a49b78df63e9cd2106.tar.gz gpg4usb-c36f2087de4f47f5f6e473a49b78df63e9cd2106.zip |
recieve signals and read properties from qml
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1054 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r-- | gpg4usb.pro | 2 | ||||
-rw-r--r-- | qml/TextField.qml | 21 | ||||
-rw-r--r-- | qml/keydetails.qml | 29 | ||||
-rw-r--r-- | qmlpage.cpp | 32 | ||||
-rw-r--r-- | qmlpage.h | 9 |
5 files changed, 67 insertions, 26 deletions
diff --git a/gpg4usb.pro b/gpg4usb.pro index 1a282ad..cd51c59 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -11,7 +11,7 @@ DEPENDPATH += . INCLUDEPATH += . #DEFINES += GPG4USB_NON_PORTABLE -DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT +#DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT CONFIG += release static #CONFIG += release diff --git a/qml/TextField.qml b/qml/TextField.qml index 1d3c12d..d60d14b 100644 --- a/qml/TextField.qml +++ b/qml/TextField.qml @@ -6,20 +6,12 @@ Rectangle { property alias text: textInput.text - //width: 100 - //height: 62 - - //Rectangle { - // id: rectangle4 - width: 114 - height: 28 - color: "#ffffff" - radius: 3 - border.width: 1 - border.color: "#999999" - //} - - + width: 114 + height: 28 + color: "#ffffff" + radius: 3 + border.width: 1 + border.color: "#999999" TextInput { id: textInput @@ -30,7 +22,6 @@ Rectangle { selectionColor: "#008000" font.pixelSize: 12 anchors.centerIn:parent - //onActiveFocusChanged: rectangle4.border.color = "#0000ff"; onActiveFocusChanged: { if (textInput.activeFocus) parent.border.color = "#0000ff"; diff --git a/qml/keydetails.qml b/qml/keydetails.qml index 106f6b9..e8a354c 100644 --- a/qml/keydetails.qml +++ b/qml/keydetails.qml @@ -1,11 +1,20 @@ import QtQuick 1.1 -FocusScope { + +//FocusScope { +Rectangle { //width: 1600 //these are the only explicit sizes set //height: 1200 //all others are relative + id: keydetails + + signal clicked + anchors.fill: parent + property alias tf1Text: tf1.text + property alias tf2Text: tf2.text + //color: "red" Rectangle { id: rectangle2 @@ -89,15 +98,17 @@ FocusScope { x: 119 y: 155 id: tf1 - text: "some other text" + text: "some text" } - Button { + /* Button { x: 246 y: 155 text: "ok" - onClicked: console.log("ok clicked, text: " + tf1.text) - } + onClicked: { + console.log("ok clicked, text: " + tf1.text) + } + }*/ TextField { x: 119 @@ -109,8 +120,12 @@ FocusScope { Button { x: 246 y: 188 - text: "ok2" - onClicked: console.log("ok2: " + tf2.text) + text: "ok" + onClicked: { + console.log("ok clicked, text: " + tf1.text) + console.log("tf2: " + tf2.text) + keydetails.clicked(); + } } diff --git a/qmlpage.cpp b/qmlpage.cpp index 277eb61..5d49f5d 100644 --- a/qmlpage.cpp +++ b/qmlpage.cpp @@ -2,7 +2,8 @@ #include <QtDeclarative/QDeclarativeView> #include <QHBoxLayout> #include <QDebug> -#include <QDeclarativeContext> +#include <QGraphicsObject> +#include <QDeclarativeProperty> QMLPage::QMLPage(KgpgCore::KgpgKey key, QWidget *parent) : @@ -14,19 +15,44 @@ QMLPage::QMLPage(KgpgCore::KgpgKey key, QWidget *parent) : // http://jryannel.wordpress.com/ // http://stackoverflow.com/questions/5594769/normal-desktop-user-interface-controls-with-qml + QDeclarativeView *qmlView = new QDeclarativeView; qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView); qmlView->setSource(QUrl("qrc:/qml/keydetails.qml")); - QDeclarativeContext *context = qmlView->rootContext(); + context = qmlView->rootContext(); context->setContextProperty("id", key.id()); context->setContextProperty("email", key.email()); context->setContextProperty("name", key.name()); - qDebug() << "qml:::::" << QUrl::fromLocalFile("keydetails.qml"); + /* + or: http://xizhizhu.blogspot.de/2010/10/hybrid-application-using-qml-and-qt-c.html + DeclarativePropertyMap map; + map.insert("key1", "value1"); + map.insert("key2", "value2"); + context->setContextProperty("map", &map); + + */ + + + // http://stackoverflow.com/questions/5947455/connecting-qml-signals-to-qt + obj = qmlView->rootObject(); + connect( obj, SIGNAL(clicked()), this, SLOT(qmlClicked())); QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setSpacing(0); mainLayout->setContentsMargins(0,0,0,0); mainLayout->addWidget(qmlView); + } + +void QMLPage::qmlClicked() { + + // http://stackoverflow.com/questions/9062189/how-to-modify-a-qml-text-from-c + qDebug() << "c++, click recieved from qml"; + qDebug() << "text1" << obj->property("tf1Text").toString(); + + //QObject *text2 = obj->findChild<QObject*>("tf2"); + qDebug() << "text2 "<< obj->property("tf2Text"); +} + @@ -2,6 +2,8 @@ #define QMLPAGE_H #include <QWidget> +#include <QDeclarativeContext> +#include <QGraphicsObject> #include "kgpg/core/kgpgkey.h" class QMLPage : public QWidget @@ -12,6 +14,13 @@ class QMLPage : public QWidget public: QMLPage(KgpgCore::KgpgKey key, QWidget *parent = 0); +public slots: + void qmlClicked(); + +private: + QDeclarativeContext *context; + QGraphicsObject *obj; + }; #endif // QMLPAGE_H |