Solved A customized widget
-
@tomy said in A customized widget:
I can't understand what the job of that SpinBox is
It's exactly the same as a normal QSpinBox, except normal spinbox uses decimal numbers (base 10) and this one uses hexadecimal (base 16). That's it. There's nothing more to it.
Is it only showing what we enter?!
Yes, exactly like a normal QSpinBox.
If so, then why when I enter 100 it shows FF?
Because it has a default range set in its constructor:
setRange(0, 255);
Which means anything bigger than 255(decimal) is clamped. 100 in hex is 256 decimal, one bigger than the maximum so it gets turned to 255 (FF in hex).
Remember that you're entering hex numbers, so anything greater than FF is clamped. If you want a bigger range you need to first callsetMaximum()
orsetRange()
with something bigger. -
@Chris-Kawa
I think I got it.
The normal SpinBox get numbers without limit. We modify its derived functions in order to make two changes: firstly, get it to get Hex numbers instead of Dec ones, and secondly, get it to have a range (a limit) of 0 to 255.
Right? -
@tomy
hi
Yes, but the range function can be called without subclassing.
The normal spin edit as a range of 0-99we subclass so we can make it take hex as input and show hex.
-
@mrjj
Yes, I think, that range setting isn't inside the virtual functions but inside the constructor so it's able to be used as an independent issue of subclassing.And please note, it here near the icon, says: "To demonstrate how to write a custom widget using this approach, we will create the IconEditor widget". To me that IconEditor is a program while it calls it a widget! If it's right, so we can call any program a widget. Yeah?
-
@tomy
Well the iconEditor uses the icon editor widget and some other stuff.
So normally you would not call a single widget a program as such but on
the other hand, qmainwindow is also a widget so sometimes an app is just one widget.
Anyway, the topic here is custom widget so dont put to much into the naming of the IconEditor. -
You can call
setRange()
from wherever you want. In the example it's used in the constructor to give that widget a sensible default value when it is created, but you can call it again later to change that range. the range 0-255 is chosen as a default because a usual use case for a hex spin box is to edit bytes, and 0-255 is the range of an 8 bit unsigned byte.If it's right, so we can call any program a widget. Yeah?
No, not really. I mean you can, but no one will know what you mean. The word "widget" means a piece of user interface, and, specifically in Qt world, it means a particular technology for creating these ui element - QWidget derived classes.
A program is a an executable that does something. One of its functions might be showing widgets, but that doesn't make a widget a program.
Think of it like this: A driving car can carry babies on the back seat but it doesn't mean you should call the baby a car :) Similarly a program can show widgets (or a single widget) but it doesn't make the widget a program ;) -
@tomy said in A customized widget:
To me that IconEditor is a program while it calls it a widget! If it's right, so we can call any program a widget. Yeah?
Come on! It is an example application to demonstrate how to write a custom widget. To be able to see this custom widget in action you need a program which uses it, right?
-
Well the iconEditor uses the icon editor widget and some other stuff.
Do we have such a widget?
I think the program subclasses QWidget and re-implements some protected functions.So normally you would not call a single widget a program as such but on
the other hand, qmainwindow is also a widget so sometimes an app is just one widget.
Anyway, the topic here is custom widget so dont put to much into the naming of the IconEditor.OK, good.
-
Hi
The widget in the sample was such widget. a custom widget.
please dont put to much in the name. its a custom widget. the name is not really important. -
@mrjj
Hi,OK, thanks.
PS: There was a really big earthquake here in my city last night when I was trying to send posts here!
-
@jsulm
Yeah, widgets are tools which are very useful for programs to use.