SOURCES += main.cpp \
widget.cpp \
myobject.cpp
HEADERS += widget.h \
myobject.h
# , qt-declarative
QT += declarative \
script
#INCLUDEPATH += # , include/qt-declarative/
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class QmlView;
class MyObject;
class Widget : public QWidget
{
Q_OBJECT
public :
explicit Widget(QWidget *parent = 0);
private :
QmlView *view;
MyObject * object ;
private slots:
void onSceneResized(QSize size);
};
#endif // WIDGET_H
* This source code was highlighted with Source Code Highlighter .
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_NoSystemBackground);
view = new QmlView( this );
view->viewport()->setAutoFillBackground( false );
* This source code was highlighted with Source Code Highlighter .
view->setFocus();
QString filename = qApp->applicationDirPath() + "/qmlpopups/default/popup.qml" ;
view->setUrl(QUrl::fromLocalFile(filename));//url - main.qml
* This source code was highlighted with Source Code Highlighter .
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
* This source code was highlighted with Source Code Highlighter .
view->rootContext()->setContextProperty( "MyObject" , object );
view->rootContext()->setContextProperty( "MyText" , "Hello, QML!" );
view->rootContext()->setContextProperty( "Avatar" ,qApp->applicationDirPath() + "/qmlpopups/default/star.png" );
* This source code was highlighted with Source Code Highlighter .
Rectangle {
id: rect
width:250
height: 100
height: Behavior { NumberAnimation { duration: 1000; easing: "InOutQuad" } }
color: "transparent"
* This source code was highlighted with Source Code Highlighter .
height: Behavior { NumberAnimation { duration: 1000; easing: "InOutQuad" } }
BorderImage {
source: "background.png"
height: rect.height
width: rect.width
border.left: 20
border.top: 20
border.bottom: 20
border.right: 20
}
* This source code was highlighted with Source Code Highlighter .
Text {
id: title
text: MyText
font.pointSize: 14
wrap: true
color: "white"
effect: DropShadow {
color: "white"
blurRadius: 2
offset.x: 0
offset.y: 0
}
anchors.top: rect.top
anchors.topMargin : 5
anchors.left: avatar.right
anchors.leftMargin : 5
}
* This source code was highlighted with Source Code Highlighter .
Text {
id: body
text: MyObject.text
font.pointSize: 12
wrap: true
color: "white"
//ancors
anchors.top: title.bottom
anchors.topMargin: 5
anchors.right: rect.right
anchors.rightMargin: 5
anchors.left: avatar.right
anchors.leftMargin : 5
onTextChanged: rect.height = calculateMyHeight();
}
* This source code was highlighted with Source Code Highlighter .
Script {
function calculateMyHeight() {
console.log( "height : " + (body.y + body.height + 20));
return (edit.y + edit.height + 20);
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/80704/