Results 1 to 7 of 7

Thread: Led widget how to setTitle

  1. #1
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3

    Default Led widget how to setTitle

    Hi all,

    i have downloaded the source code for LED program from Qt applications website. i was successful in using the Led i was able to change the color to red, green etc. Now my main problem is i have created 20 similar Led's and i want to give some title to each led like led1, led2 etc to recognize which is ON or OFF, but i am not able to do it using setTitle function. could somebody please help me how to modify the program to give the title to each led. i am very much new to QT and i do not how to do it. i have been struggling to do this for the past several weeks, but not successful.

    Thanks in advance for any support,

    regards,
    Satya

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Led widget how to setTitle

    QLabel and a layout of some sort.

    Unless you want to tell us exactly what you downloaded, where from, and what you have done with it there is little chance of more specific answers.

  3. #3
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3

    Default Re: Led widget how to setTitle

    sorry for the incomplete information this is the path from which i have downloaded the source code from the following link http://qt-apps.org/content/download....1&tan=36155544. In the downloaded folder i used led related files into my project which i have attached in the present reply. Currently i am facing the problem of setting the text. please guide me or please send me the modified code so that i can set the text of led which i plan to implement like [code]Led *led1 = new Led("LED1")[\code]. (First time i am using BB code as i got warning last time. please correct me if i have not properly used it).

    thanks in advance,
    regards,
    satya
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3

    Default Re: Led widget how to setTitle

    Hi all,

    Could somebody please suggest me how to solve the above problem?

    thanks and regards,
    Satya

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Led widget how to setTitle

    You already have it.

    The LED widget you are using does not have a facility to label itself. You have to label it separately, which is why I suggested a QLabel and layout above.

  6. #6
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3

    Default Re: Led widget how to setTitle

    Thank you for the help. yeah some how i managed to do it with QLabel and gridlayout but i could not get confidence on what i am doing, but is it possible for me to implement Led to label itself. i tried using QProperty but was not successful. Also i tried to qlabel with absolute positioning and led with grid layout but the absolute positioning does not seem to work as it always positions at a fixed position even if i change the position using setGeometry().

    thanks and regards,
    satya

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Led widget how to setTitle

    but is it possible for me to implement Led to label itself
    Yes, you would have to modify the LED API to give you a label getter/setter, some good size hinting, and the paintEvent() to render the text in the relevant location with respect to the LED graphic. It would be easier to leave the LED code alone and create your own composite widget class with a layout containing a label and LED. The composite class should expose a way to set the label text, perhaps through the constructor, and LED colour/state. This is very basic C++ and Qt.
    i tried to qlabel with absolute positioning and led with grid layout but the absolute positioning does not seem to work as it always positions at a fixed position even if i change the position using setGeometry().
    The point of layouts is that you do not worry about positioning... that's the job of the layout using the constraints and content you give it.

    Something like this (untested):
    Qt Code:
    1. class MyLED: public QWidget {
    2. Q_OBJECT
    3. public:
    4. MyLED(QWidget *p = 0): QWidget(p) {
    5. m_LED = new LED(this);
    6. m_label = new QLabel(this);
    7. VBoxLayout *layout = new QVBoxLayout;
    8. layout->addWidget(m_led);
    9. layout->addWidget(m_label);
    10. // tweak layout constraints as required
    11. setLayout(layout);
    12. }
    13. void setText(const QString &text) { m_label->setText(text); }
    14. void setLEDColour(...) { }
    15. void setLEDState(...) { }
    16.  
    17. private:
    18. LED *m_led;
    19. QLabel *m_label;
    20. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 2nd February 2012, 19:52
  2. Replies: 2
    Last Post: 23rd January 2012, 17:06
  3. Replies: 8
    Last Post: 28th June 2011, 14:57
  4. Replies: 1
    Last Post: 23rd June 2011, 23:09
  5. Replies: 4
    Last Post: 3rd March 2008, 22:15

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.