Answer the question
In order to leave comments, you need to log in
QLineedit: how to split a number into digits when typing (1500000) to (1,500,000)?
As an example of a calculator in Windows 7, when entering a number, it automatically breaks into digits [8 696 000] how to implement this in Qt? QLineedit has a setInputMask method but it allows you to enter numbers of a fixed length (999 999) it will allow you to enter 6 characters no more, no less ... The Validator checks the input for compliance, but does not change the input format ... There is also a QLocale that seems to do what needed ... but it leads to the desired format of an already entered value ...
So for label it fits
connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(FormatText()));
void Dialog::FormatText()
{
ui->label_2->setText(QString("%L1").arg(ui->lineEdit->text().toDouble(),0,'f',0,' '));
}
Answer the question
In order to leave comments, you need to log in
Create your own class, inherit from QLineEdit and override some methods to implement your task.
For example, if the widget is read only and you use the insert method, override it, validate the incoming text and add spaces where necessary, then call insert on the base class.
If the user enters the numbers himself, you need to catch the appearance of a new character (or deletion), read the text, add or remove spaces.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question