Results 1 to 1 of 1

Thread: Displaying LCD Widget of Qt in QML

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Displaying LCD Widget of Qt in QML

    The following code compiles properly but shows NOTHING on QML window.

    .cpp

    Qt Code:
    1. #include "q.h"
    2.  
    3. Lcdnumber :: Lcdnumber(QGraphicsItem *parent) : QGraphicsProxyWidget(parent)
    4. {
    5. number = new QLCDNumber();
    6. number->display(11);
    7. }
    8.  
    9. int main (int argc, char *argv[])
    10. {
    11. QApplication app (argc, argv);
    12.  
    13. qmlRegisterType <Lcdnumber> ("Q", 1, 0, "Lcdnumber");
    14.  
    15. QDeclarativeView view;
    16. view.setSource (QUrl :: fromLocalFile ("qq.qml"));
    17. view.show ();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    .h

    Qt Code:
    1. #ifndef LCDNUMBER_H
    2. #define LCDNUMBER_H
    3.  
    4. #include <QtDeclarative/QDeclarativeExtensionPlugin>
    5. #include <QtDeclarative/qdeclarative.h>
    6. #include <QGraphicsProxyWidget>
    7. #include <QDebug>
    8.  
    9. #include <qdeclarative.h>
    10. #include <QDeclarativeView>
    11. #include <QApplication>
    12.  
    13. #include <QWidget>
    14. #include <QLCDNumber>
    15.  
    16.  
    17. class Lcdnumber : public QGraphicsProxyWidget
    18. {
    19. Q_OBJECT
    20.  
    21. public:
    22. Lcdnumber(QGraphicsItem *parent = 0);
    23.  
    24. ~Lcdnumber() {}
    25.  
    26. private:
    27. QLCDNumber* number;
    28. };
    29.  
    30. #endif // LCDNUMBER_H
    To copy to clipboard, switch view to plain text mode 

    qml

    Qt Code:
    1. import QtQuick 1.0
    2. import Q 1.0
    3.  
    4. Rectangle
    5. {
    6. id: window
    7. Lcdnumber
    8. {
    9. id: button1
    10. anchors.centerIn: parent
    11. width: 600; height: 600
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 




    SOLVED

    I forgot to add:
    Qt Code:
    1. setWidget (number);
    To copy to clipboard, switch view to plain text mode 

    in constructor.
    Last edited by TheIndependentAquarius; 22nd October 2013 at 11:36. Reason: updated contents

Similar Threads

  1. Displaying a eml file in a widget
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2013, 17:36
  2. QWT in QT: displaying qwt plot as widget on mainwindow
    By zaidi1212 in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2013, 15:10
  3. Replies: 1
    Last Post: 27th February 2011, 08:15
  4. Displaying 1 widget at time
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2008, 15:31
  5. Displaying Page Number on a widget
    By LiCodeX in forum Newbie
    Replies: 1
    Last Post: 23rd August 2007, 08:34

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.