Results 1 to 13 of 13

Thread: a countdown widget

  1. #1
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question a countdown widget

    Hi, I need a widget to countdown - to display it over a webcam display, before I capture a photo. Have you seen anything alike?

  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: a countdown widget

    Count down what? Have you seen QLCDNumber?

  3. #3
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    To countdown, you know, like before a rocket launch

    I've seen the QLCDNumber and other standard Qt widgets. The question was if somebody has seen a widget meant precisely for countdown - it's all about reusability, isn't it?

  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: a countdown widget

    Hmm... what's wrong with QLCDNumber? Reusability means exactly that you should reuse an existing component for different tasks, not that you should look if someone already had a similar problem...

  5. #5
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    If somebody had a similar problem, and solved it, then a component doing a nice countdown already exists... and I would like to reuse it

    The thing with QLCDNumber is that it only displays a number. And I need to do an animation, like 3... 2... 1... boom - with a good timing and possibly some sound in parallel. Moreover, I'm not so sure if I would like to use an LCD-look.

  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: a countdown widget

    Ok, tell me what do you want then, and I'll give you code that does what you want. Satisfied?

  7. #7
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    No no... It's not what I meant. I'll wait a couple of days and if I see that nobody had prepared such a widget before, I'll do it myself.

    I wouldn't ask anybody to do my job for me - I only wander if I could reuse something somebody has already done for himself before. Isn't this forum a place of such exchange among developers using Qt? (I'm asking this question because from your posts, Wysota, I get an impression that I did something strange here...)

  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: a countdown widget

    Long story short - you won't get a "countdown widget" from anyone, because if someone needed it, he would use QLCDNumber or QLabel with a QTimer - ten lines of code total (twenty if you want a more capable version). And that's exactly what I call code reuse - you use QLCDNumber or QLabel for different things.

    Even shorter - you are wasting your time waiting a week for something you would acomplish yourself in 5 minutes.

  9. #9
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    You think I was doing nothing but waiting? It's just my idle time - looking at this forum

    Thanks for your opinion, anyway. It's curious, though, how you can answer in the name of all Qt users...

  10. #10
    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: a countdown widget

    Quote Originally Posted by anarsynd View Post
    It's curious, though, how you can answer in the name of all Qt users...
    If you hang out here for two years, you'll know why...

    Here is the promised implementation, you can base on it to create your own:

    Qt Code:
    1. class CountDownWidget : public QLCDNumber {
    2. Q_OBJECT
    3. public:
    4. CountDownWidget(QWidget *parent=0) : QLCDNumber(parent){ m_id = -1;}
    5. public slots:
    6. void start(int val=-1){ if(val>=0) display(val); m_id = startTimer(1000); }
    7. void stop(){ killTimer(m_id);}
    8. signals:
    9. void timeout();
    10. protected:
    11. void timerEvent(QTimerEvent *e){
    12. display(value()-1);
    13. if(value()<=0){ killTimer(m_id); m_id = -1; display(0); emit timeout(); return;}
    14. }
    15. };
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to wysota for this useful post:

    anarsynd (20th November 2007)

  12. #11
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    Thanks for the code - I'll build on it :-)

    And for the sound part? What would you use to play a wave file each time the displayed number changes?

  13. #12
    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: a countdown widget

    Quote Originally Posted by anarsynd View Post
    And for the sound part? What would you use to play a wave file each time the displayed number changes?
    Well... currently QSound is the only option. Since Qt 4.4 you'll be able to use anything Phonon offers.

  14. #13
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a countdown widget

    Then I guess I know all I need. Thanks.

Similar Threads

  1. Replies: 3
    Last Post: 17th October 2007, 13:52
  2. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 18:52
  3. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 15:27
  4. Replies: 4
    Last Post: 24th March 2006, 23:50
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16

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.