Page 1 of 1
NUMGETC - Introducing a new HMG4 class
Posted: Sun Dec 25, 2011 3:59 pm
by Ricci
"Back to basics" was my intention when creating this new class. While the Textbox class is getting more and more complex, I thought of creating a simple numeric input field.
Do you know the Windows Calculator? When using the keyboard only numeric keys, comma/point and backspace are available. Simple, safe and effective to enter numbers. The numbers are always right aligned and no cursor has to be used.
That´s the way the NUMGETC control (NUmeric GET Calculator) is working.
You define it with
Code: Select all
DEFINE NUMGETC oNumGet1
ROW 20
COL 420
WIDTH 160
HEIGHT 20
FORMAT "."
THOUSENDS .F.
DECIMALS 2
END NUMGETC
FORMAT is the decimal point, you can choose between "." (US), "," (European) and "A" (automatic). "A" only works well, if you set the language and country in your before with HMGAPP():Localized( <language>, <country> ).
When THOUSENDS are set to .T. you see the thousends delimiter (even at the input).
With DECIMALS you set the number of decimals than can be used.
No coursor, no copy, no paste support - I wanted to keep it simple.
And not perfect

- I hate it when you enter the field using Tab key and the existing number is marked. Perhaps someone find a way to get rid of it.
Ricci
Re: NUMGETC - Introducing a new HMG4 class
Posted: Sun Dec 25, 2011 7:29 pm
by mrduck
Really nice Ricci !!!
Just a couple of things:
Perhaps the german "tausend" confused you, in english is thousand.
No coursor, no copy, no paste support - I wanted to keep it simple.
And not perfect

- I hate it when you enter the field using Tab key and the existing number is marked. Perhaps someone find a way to get rid of it.
It's still based on QLineEdit. I didn't try it now but I think that cut & paste works and can create some problems... why don't you base it on QLabel ? set strong focus on it and it shoud work as expected... just set different colors to simulate a QLineEdit or to make it different from a QLabel...
It will also solve the "select all" problem...
Re: NUMGETC - Introducing a new HMG4 class
Posted: Sun Dec 25, 2011 8:18 pm
by mrduck
A couple more...
In :create() there is the code for disabled font/back colors. I added some weeks ago a couple of methods that uses standard Qt QPalette way of setting colors, without needing CSS..
It should be changed in Textbox() also...
I'm also thinking about a small redesign of some methods and their inheritance... but if ever, it will be in the future...
Re: NUMGETC - Introducing a new HMG4 class
Posted: Sun Dec 25, 2011 8:38 pm
by Ricci
Francesco, QLabel is better for sure but how can I give him the same look like a QLineEdit. Setting the border is no problem but the colors should be the same depending on the theme. I have to assign the palette from QLineEdit to the QLabel ... but how?
Re: NUMGETC - Introducing a new HMG4 class
Posted: Sun Dec 25, 2011 8:55 pm
by mrduck
Ricci wrote:I have to assign the palette from QLineEdit to the QLabel ... but how?
Try adapting this:
https://developer.qt.nokia.com/forums/viewthread/5220
and read this:
https://developer.qt.nokia.com/forums/viewthread/487
and
https://www.qtforum.org/article/26805/ql ... color.html
for some ideas.
I think you should create a QLabel, a QLineEdit, get QLineEdit palette and use it on QLabel, finally destroy QLineEdit...
Re: NUMGETC - Introducing a new HMG4 class
Posted: Mon Dec 26, 2011 9:15 am
by Rathinagiri
Hi
It looks very promising! Great job.
Re: NUMGETC - Introducing a new HMG4 class
Posted: Mon Dec 26, 2011 11:16 am
by Ricci
OK, NUMGETC is now based on QLabel.
Re: NUMGETC - Introducing a new HMG4 class
Posted: Sun Jan 01, 2012 4:31 pm
by Ricci
NUMGETC now displays a grafic arrow when having the focus.
The grafic is build at runtime from code using the new function Xpm2Image(). This function should not be necessary, because one can assign a XPM to QImage at define ... if he don´t use Harbour.
Perhaps someone find a way how to use "QImage ( const char * const[] xpm )" - that would be great. I spend a lot of time and didn´t get it to work. So I wrote the conversion function.
NUMGETC became a compound object, consisting of a QLabel for the number and another QLabel for displaying/hiding the grafic.
I think that the code is worth a look - to get a feeling how to combine 2 or more objects to one.