Results 1 to 4 of 4

Thread: Do I need a delegate for double numbers in a QStandardItemModel?

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    1. avoid conversion errors (double to string and vice versa)
    2. when I append a new row the new default delegate is just a string one
    3. 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Do I need a delegate for double numbers in a QStandardItemModel?

    Quote Originally Posted by fatecasino View Post
    if I don't initialize the cell it's a string delegate
    There is no such thing as a "string delegate".

    if I initialize it with an int it's like a spinbox delegate
    same as above

    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.

    • 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QtableWidget and numbers of row
    By VitaliBR in forum Newbie
    Replies: 8
    Last Post: 3rd February 2011, 23:32
  2. how convert numbers into text
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 5th August 2009, 10:01
  3. Replies: 2
    Last Post: 24th June 2009, 15:38
  4. Complex Numbers
    By Max Yaffe in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2007, 17:40
  5. Column with numbers
    By ederbs in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 22:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.