PDA

View Full Version : QML files in QT application



nageshvk
26th November 2010, 05:16
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

wysota
26th November 2010, 12:16
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.

nageshvk
26th November 2010, 13:19
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

wysota
26th November 2010, 13:48
How to add the graphics scene to layout.
You don't add scenes to layouts. Scene is a purely logical component.

and render them into pixmaps.
QGraphicsScene::render()

nageshvk
29th November 2010, 05:36
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.


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);
QGraphicsScene scene;
scene.addItem(gwidget);


QLabel *label = new QLabel();

QPixmap pixmap(100,100);
QPainter painter(&pixmap);
scene.render(&painter);
label->setPixmap(pixmap);
QWidget widget;
QGridLayout layout( &widget );
layout.addWidget(label);
widget.show();

wysota
29th November 2010, 10:29
Please provide a compilable example.

nageshvk
30th November 2010, 11:26
Hi,

I am getting all the time this error. How to solve this issue
here engine is QDeclaraviteEngine and filename is some .qml file.


QDeclarativeComponent component(engine, QUrl::fromLocalFile(fileName));
QObject *myObject;
do{
myObject= component.create();
}while(!component.isReady());
QGraphicsItem* item = qobject_cast<QGraphicsItem*>(myObject);



QDeclarativeComponent: Component is not ready

Regards
Nagesh

wysota
30th November 2010, 11:37
This is not a compilable example.

nageshvk
1st December 2010, 08:03
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


QPushButton *pushButton = new QPushButton();
QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml file"));
QObject *myObject;
do{
myObject= component.create();
}while(!component.isReady());
QGraphicsItem* item = qobject_cast<QGraphicsItem*>(myObject);

QGraphicsScene scene;
scene.addItem(item);

QPixmap pixmap(100,100);

QPainter painter(&pixmap);
scene.render(&painter);

QIcon icon(pixmap);
pushButton->setIconSize(QSize(100,100));
pushButton->setFlat(true);
pushButton->setIcon(icon);
pushButton->setToolTip(fileName);


naag