Do I need a delegate for double numbers in a QStandardItemModel?
I want to use a scientific QStandardItemModel model which will receive some values from comboboxes and some double numbers that the user will insert in a QTableView. I successfully managed to implement the delegate for the combobox. Do I need to program seperately a delegate for the cells that the user inserts a double number? Perhaps it would be good to protect the program by not allowing the user to insert any other value (characters, symbols) in the cells for double numbers.
Re: Do I need a delegate for double numbers in a QStandardItemModel?
Have you tried how does the default delegate acts by default before you posted this question?
Re: Do I need a delegate for double numbers in a QStandardItemModel?
yes,
- if I don't initialize the cell it's a string delegate
- if I initialize it with an int it's like a spinbox delegate
- if I initialize it with a double number like 0.1 it's again like a spinbox delegate BUT it does not allow me to insert more than 2 decimal digits(why?!)
The reasons I am asking are:
- avoid conversion errors (double to string and vice versa)
- when I append a new row the new default delegate is just a string one
- protect the system and allow the user to insert only valid values (just doubles, not symbols or characters)
Therefore, I am asking if there is an option or a default delegate for double numbers
Re: Do I need a delegate for double numbers in a QStandardItemModel?
Quote:
Originally Posted by
fatecasino
if I don't initialize the cell it's a string delegate
There is no such thing as a "string delegate".
Quote:
if I initialize it with an int it's like a spinbox delegate
same as above
Quote:
if I initialize it with a double number like 0.1 it's again like a spinbox delegate BUT it does not allow me to insert more than 2 decimal digits(why?!)
Because the widget returned has default properties and the default properties of QDoubleSpinBox are such that they allow a default number of digits and a default range.
Quote:
- avoid conversion errors (double to string and vice versa)
- when I append a new row the new default delegate is just a string one
- protect the system and allow the user to insert only valid values (just doubles, not symbols or characters)
I think you need to read more what a delegate is and how the model-view framework in Qt works.