Results 1 to 12 of 12

Thread: How to have a QSpinBox for setting a specific time?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to have a QSpinBox for setting a specific time?

    Hello!

    It's probably an easy one, because I've seen it many times.

    1st of all, I don't seem to be able to find how to set the format of a spinbox, because I need it to say 00 instead of 0 and to be able to take multiple values, just like the spinbox that exist in windows 7 when you are about to change the time: http://i.imgur.com/e8cIv.jpg (except that i don't need the seconds, I am only interested in minutes and hours in 24-hour format, not 12 with AM and PM)

    Anybody has an idea of where should I start of?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to have a QSpinBox for setting a specific time?

    QDateTimeEdit::setDisplayFormat();

  3. The following user says thank you to pkj for this useful post:

    hakermania (15th January 2012)

  4. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to have a QSpinBox for setting a specific time?

    Hello pkj, thanks for the answer. Could you please be more specific? (see my sig)
    I read the documentation but I don't know how this could be related with a QSpinBox.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by hakermania View Post
    Hello pkj, thanks for the answer. Could you please be more specific? (see my sig)
    Your signature is foolish!
    I read the documentation
    This is what newbies should do. Over and over again. (My lawyer advised me to add: Related to this very very simple problem!)
    but I don't know how this could be related with a QSpinBox.
    Maybe in NOT using QSpinBox? You want to edit a time, not a number -> QDateTimeEdit as suggested.

  6. The following user says thank you to Lykurg for this useful post:

    hakermania (15th January 2012)

  7. #5
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to have a QSpinBox for setting a specific time?

    Lykurg my friend, no need to be so aggressive, my sig isn't foolish, I highly support that somebody learns best through examples and I've proven it (to myself) several times.

    Back to the topic now, I think that I was specific, I *need* to use a QSpinBox, for my own reasons.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  8. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by hakermania View Post
    I *need* to use a QSpinBox, for my own reasons.
    QDateTimeEdit is a spin box and provides you with the ability to display [00-24]:[00-60], what is what you want. (when I've understood you right) If you what still use a QSpinBox for your own reasons, then write your own "delegate" for the box. See "Spin Boxes Example", see the detailed description of QSpinBox "Subclassing QSpinBox" ... and end with a own written QDateTimeEdit!

  9. The following user says thank you to Lykurg for this useful post:

    hakermania (15th January 2012)

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

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by hakermania View Post
    Lykurg my friend, no need to be so aggressive, my sig isn't foolish, I highly support that somebody learns best through examples and I've proven it (to myself) several times.
    So after writing 224 posts (and at least 18 months of familarity with Qt) you still consider yourself a newbie? So what have you learned during those 18 months?

    Back to the topic now, I think that I was specific, I *need* to use a QSpinBox, for my own reasons.
    Ok, so to be specific: the widget image of which you posted is *not* a spin box. At least not more than QDateTimeEdit is. Both are widgets meant for entering time and both are spinbox-like.

    However if you really really really need to use QSpinBox, subclass it and reimplement QSpinbox::textFromValue() and QSpinBox::valueFromText() to transform integer values to text and vice versa.
    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.


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

    hakermania (15th January 2012)

  12. #8
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by wysota View Post
    So after writing 224 posts (and at least 18 months of familarity with Qt) you still consider yourself a newbie? So what have you learned during those 18 months?
    No, I won't consider myself a newbie, but because of the fact that Qt is huge, I haven't used everything and I am possibly not going to, so everything that is new to me I post it to the newbie section, it isn't something that I've used and thus I know how to use it but I have problem with it... Plus the fact that I am not all the time programming, heh.
    As for what I've learned about Qt, I've learned to handle many things, such as signals and slots, and I can now already know how to use *some* of the things I've never used before due to similarities.

    But, honestly now, QDateTimeEdit is not the most usual thing on earth so as to know it. And that pic of Windows time setting is very similar to a spinbox..

    Ok, subclassing will take place, thank you both!
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  13. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by hakermania View Post
    Ok, subclassing will take place, thank you both!
    Because I ask me why you want to subclass, please tell me what exactly you need. What are your requirements?

  14. #10
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by Lykurg View Post
    Because I ask me why you want to subclass, please tell me what exactly you need. What are your requirements?
    This is top secret. Seriously.
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

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

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by hakermania View Post
    No, I won't consider myself a newbie,
    So what you have written doesn't apply to you?

    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.
    If so, then why are you pointing us at your signature?

    But, honestly now, QDateTimeEdit is not the most usual thing on earth so as to know it.
    I would tend to disagree.

    And that pic of Windows time setting is very similar to a spinbox..
    On my monitor it looks exactly like QTimeEdit / QDateTimeEdit...

    timeedit.png
    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.


  16. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to have a QSpinBox for setting a specific time?

    Quote Originally Posted by wysota View Post
    Brilliant! You both have taken the screen shot at the same time...

    Over and out.

Similar Threads

  1. QSpinBox setting buttons with using stylesheets
    By _franko_ in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2011, 21:09
  2. Replies: 5
    Last Post: 12th April 2011, 09:03
  3. setting date and time
    By nighil in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2011, 15:32
  4. Setting specific entries of a QComboBox to appear Bold
    By prykHetQuo in forum Qt Programming
    Replies: 7
    Last Post: 23rd March 2009, 23:11

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
  •  
Qt is a trademark of The Qt Company.