I second the idea of using a spin box instead of a line edit. But if you really want a pure line edit, implement a validator that would introduce the missing symbols into the text. Unfortunately you'll have to strip those symbols from the text before writing it to the database, so a spin box is a better solution.
Ok I'm working on QSpinBox using prefix("$"), but don't know how get dots separators.
Reimplement textFromValue() and textToValue() methods.
I needed the same thing in my program. Here is the code that i think help you to figure this out. By usingyou can convert 57836 to 57.836Qt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
{ int len = what.length(); QString buffer; int i; for(i=0; i<len ; i++) buffer[i]=what[len-i-1]; return buffer; } { int len = what.length(); int sira; int deviation=0; for(sira=kdabir; sira<len ;sira=(sira+(1*kdabir)) ) { buffer.insert(sira+deviation, add); deviation++; } return reverse(buffer); }To copy to clipboard, switch view to plain text mode
Last edited by ocean; 11th September 2008 at 21:53.
Hmm... how about simply:
Qt Code:
To copy to clipboard, switch view to plain text mode
Yes, your solution works perfect! (and simpler). But if you want to handle much bigger numbers, you need to use more flexible code. Because your code won't render two or more DOTs and also you won't be able to use any type of decimal numbers. (I use this code to convert i.e. 12536.89 to 12.536,89). To be honest, i think i will never have to enter 1.000.000$ into my LineEdit-and i don't think you will need that in near future too, am i right?-, but sometimes it's good to know that you have a function that can handle any type of argument, in this situation, big numbers.
Last edited by ocean; 11th September 2008 at 22:01.
Group separators in numbers are locale specific. QLocale would handle those for you.
J-P Nurmi
Bookmarks