PDA

View Full Version : How to have a QSpinBox for setting a specific time?



hakermania
15th January 2012, 16:43
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?

pkj
15th January 2012, 18:49
QDateTimeEdit::setDisplayFormat();

hakermania
15th January 2012, 19:45
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.

Lykurg
15th January 2012, 19:54
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.

hakermania
15th January 2012, 20:09
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.

Lykurg
15th January 2012, 20:26
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!

wysota
15th January 2012, 20:32
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.

hakermania
15th January 2012, 20:49
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!

Lykurg
15th January 2012, 20:56
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?

hakermania
15th January 2012, 21:03
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.

wysota
15th January 2012, 21:34
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...

7273

Lykurg
15th January 2012, 22:28
7273Brilliant! You both have taken the screen shot at the same time...

Over and out.