QML files in QT application
hi,
I have a QTableview object in my application and a list of QML files.
I Need to show the files in thumbnail view.
--|----|-----------
1 |ABC
-------|-----------
2 |XYZ
If i select ABC then correspoding ABC.QMl file should be opened and showed on my QT application. Until then all QML files must be shown as thumbnails in my application.
Could you please suggest me how to start do it.
Regards
Nagesh
Re: QML files in QT application
Use QDeclarativeComponent to load your qml files. Place the objects in a graphics scene and render them into pixmaps to get the thumbnails. As for the main file, just load it on demand into QDeclarativeView or simply move the object used to get the thumbnail to a QGraphicsScene connected to your main graphics view.
Re: QML files in QT application
I have used QDeclarativeComponent for loading the QML files.
Using graphics scene i am able to add to widgets....But it is not display when i run the QT application.
Can you please tell me in details after adding the QML files to graphics scene.... How to add the graphics scene to layout. and render them into pixmaps.
I am very new to QT and QML programming...hope u wont mind if i am wrong.
Thanks
Nagesh
Re: QML files in QT application
Quote:
Originally Posted by
nageshvk
How to add the graphics scene to layout.
You don't add scenes to layouts. Scene is a purely logical component.
Quote:
and render them into pixmaps.
QGraphicsScene::render()
Re: QML files in QT application
Hi,
Thanks for the response....I wrote this below piece of code. When i run this code....i am getting a black screen image rather than getting the actual image. Could you please let me know where i am doing wrong.
Thanks in advance.
Code:
QGraphicsWidget *gwidget = new QGraphicsWidget();
QGraphicsLinearLayout *glayout = new QGraphicsLinearLayout();
QDeclarativeEngine engine;
QDeclarativeComponent c
(&engine,
QUrl(":screen.qml"));
QGraphicsLayoutItem* obj = qobject_cast<QGraphicsLayoutItem*>(c.create());
glayout->addItem(obj);
gwidget->setLayout(glayout);
scene.addItem(gwidget);
scene.render(&painter);
label->setPixmap(pixmap);
layout.addWidget(label);
widget.show();
Re: QML files in QT application
Please provide a compilable example.
Re: QML files in QT application
Hi,
I am getting all the time this error. How to solve this issue
here engine is QDeclaraviteEngine and filename is some .qml file.
Code:
QDeclarativeComponent component
(engine,
QUrl::fromLocalFile(fileName
));
do{
myObject= component.create();
}while(!component.isReady());
QDeclarativeComponent: Component is not ready
Regards
Nagesh
Re: QML files in QT application
This is not a compilable example.
Re: QML files in QT application
Thank you very much.... I have tried the way u explained to me.....It is working absolutely fine.
Thank you once again....here is the piece of code for any needy
Code:
QDeclarativeComponent component
(engine,
QUrl::fromLocalFile("qml file"));
do{
myObject= component.create();
}while(!component.isReady());
scene.addItem(item);
scene.render(&painter);
pushButton
->setIconSize
(QSize(100,
100));
pushButton->setFlat(true);
pushButton->setIcon(icon);
pushButton->setToolTip(fileName);
naag