Results 1 to 9 of 9

Thread: QML files in QT application

  1. #1
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML files in QT application

    Quote Originally Posted by nageshvk View Post
    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()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.

    Qt Code:
    1. QGraphicsWidget *gwidget = new QGraphicsWidget();
    2. QGraphicsLinearLayout *glayout = new QGraphicsLinearLayout();
    3.  
    4. QDeclarativeEngine engine;
    5. QDeclarativeComponent c(&engine, QUrl(":screen.qml"));
    6. QGraphicsLayoutItem* obj = qobject_cast<QGraphicsLayoutItem*>(c.create());
    7.  
    8. glayout->addItem(obj);
    9. gwidget->setLayout(glayout);
    10. scene.addItem(gwidget);
    11.  
    12.  
    13. QLabel *label = new QLabel();
    14.  
    15. QPixmap pixmap(100,100);
    16. QPainter painter(&pixmap);
    17. scene.render(&painter);
    18. label->setPixmap(pixmap);
    19. QWidget widget;
    20. QGridLayout layout( &widget );
    21. layout.addWidget(label);
    22. widget.show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 29th November 2010 at 10:27. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML files in QT application

    Please provide a compilable example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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.

    Qt Code:
    1. QDeclarativeComponent component(engine, QUrl::fromLocalFile(fileName));
    2. QObject *myObject;
    3. do{
    4. myObject= component.create();
    5. }while(!component.isReady());
    6. QGraphicsItem* item = qobject_cast<QGraphicsItem*>(myObject);
    To copy to clipboard, switch view to plain text mode 



    QDeclarativeComponent: Component is not ready

    Regards
    Nagesh
    Last edited by wysota; 30th November 2010 at 11:38. Reason: missing [code] tags

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML files in QT application

    This is not a compilable example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2010
    Posts
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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

    Qt Code:
    1. QPushButton *pushButton = new QPushButton();
    2. QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml file"));
    3. QObject *myObject;
    4. do{
    5. myObject= component.create();
    6. }while(!component.isReady());
    7. QGraphicsItem* item = qobject_cast<QGraphicsItem*>(myObject);
    8.  
    9. scene.addItem(item);
    10.  
    11. QPixmap pixmap(100,100);
    12.  
    13. QPainter painter(&pixmap);
    14. scene.render(&painter);
    15.  
    16. QIcon icon(pixmap);
    17. pushButton->setIconSize(QSize(100,100));
    18. pushButton->setFlat(true);
    19. pushButton->setIcon(icon);
    20. pushButton->setToolTip(fileName);
    To copy to clipboard, switch view to plain text mode 


    naag
    Last edited by wysota; 1st December 2010 at 09:44. Reason: missing [code] tags

Similar Threads

  1. Replies: 5
    Last Post: 27th July 2011, 20:02
  2. Replies: 0
    Last Post: 21st June 2010, 11:59
  3. To identify executable and other files in QT Application
    By augusbas in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2010, 19:29
  4. Installation of application data files
    By anderssonj in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 17:02
  5. How to open IGES files in Qt Application?
    By Shuchi Agrawal in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 02:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.