Qml in qt widgets
-
Hello guys,
im trying to display qml object on std qt widget.
I found some tips on the net but still app doesn't work.@///< ---- my code
this->vbox_main=new QVBoxLayout();//layout generation this->viewQML = new QQuickView(); this->containerQML = QWidget::createWindowContainer(this->viewQML, this); this->containerQML->adjustSize(); this->containerQML->setFocusPolicy(Qt::TabFocus); this->viewQML->setSource(QUrl("UpdateAnim.qml")); this->vbox_main->addWidget(this->containerQML,1,Qt::AlignHCenter); this->label_status=new QLabel(this); this->label_status->setText("Status"); this->vbox_main->addWidget(this->label_status,1,Qt::AlignHCenter); this->setLayout(this->vbox_main); this->setMinimumSize(400,200);
///< ---- the end of my code
@Does anybody know what im doing wrong ?
Best regards
Thomas[edit: Added missing coding tags @ SGaist]
-
Hi,
Invalid qml file path ?
-
No, because when it was wrong Qt Creator said me that in output...
-
I just created new QtUI application project and did the following. It works perfectly.
What is 'this' object in your case ? It is QMainWIndow or QWidget ?
@QWidget *wid = new QWidget;
QPushButton *butt = new QPushButton("pthinks.com");
QVBoxLayout *lyt = new QVBoxLayout(wid);
lyt->addWidget(butt);
QQuickView *view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(view, this);
container->setMinimumSize(200, 200);
container->setMaximumSize(200, 200);
container->setFocusPolicy(Qt::TabFocus);
view->setSource(QUrl("main.qml"));
lyt->addWidget(container);
wid->show();@ -
QDialog
-
I have replaced QWidget *wid = new QWidget;
with
QDialog *wid = new QDialog;in above code snippet. It works perfectly. When you launch your program, what is shown ? Is the dialog shown ? Only QML Window is missing ?
-
The content of qml is not displayed.
It's look like the place for it is prepared.//code of qml file
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0Rectangle {
id: recMain
height : 100
width : 100
Button
{
text:"hoho"
}AnimatedImage { id : buttonImage source : "gfx/loading.png" anchors.horizontalCenter : recMain.horizontalCenter anchors.verticalCenter : recMain.verticalCenter NumberAnimation on rotation { from : 0; to : 360; running : buttonImage.visible = true; loops : Animation.Infinite; duration : 1000; } }
}
//the end of code of qml file
I put the button to se if maybe only png file is not loaded.
-
Hi,
See if you get any errors using "errors":http://qt-project.org/doc/qt-5/qquickview.html#errors function.
-
It must be issue with QML file only. Either it is path issue with QML file itself or image file issue. Hope you are able to run the QML file directly. You can try adding QMLFile and ImageFile in Resource file and refer it. It may solve your issue.
-
Ok, I will check it, but later becuase Im on my job now :P
Thanks all for help. Will write when I check all possibilities
-
Hi,
I already know where was the problem.
I didn't set size of container and thus of that there was no place to display qml object.Strange, because it's hard to set ( probably for me :) ) right size policy between qml object and container widget.
If someone have some good examples where qml objects are combined with Qt widgets I will be thankful.