NUMGETC - Introducing a new HMG4 class

Moderator: Rathinagiri

Post Reply
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

NUMGETC - Introducing a new HMG4 class

Post 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
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: NUMGETC - Introducing a new HMG4 class

Post by mrduck »

Really nice Ricci !!!

Just a couple of things:
Ricci wrote:

Code: Select all


					 THOUSENDS	.F.	
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...
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: NUMGETC - Introducing a new HMG4 class

Post 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...
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: NUMGETC - Introducing a new HMG4 class

Post 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?
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: NUMGETC - Introducing a new HMG4 class

Post by mrduck »

Ricci wrote:I have to assign the palette from QLineEdit to the QLabel ... but how?
Try adapting this: http://developer.qt.nokia.com/forums/viewthread/5220
and read this: http://developer.qt.nokia.com/forums/viewthread/487
and http://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...
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: NUMGETC - Introducing a new HMG4 class

Post by Rathinagiri »

Hi

It looks very promising! Great job.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: NUMGETC - Introducing a new HMG4 class

Post by Ricci »

OK, NUMGETC is now based on QLabel.
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: NUMGETC - Introducing a new HMG4 class

Post 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.
Post Reply