[SOLVED] How to force a tableView to only display and accept hex numbers?



  • I have a tableView in my GUI design. I'd like to use tableView for presenting 32-bit hexadecimal numbers only. How can I force my tableView to only display and accept hex numbers?

    Thanks


  • Lifetime Qt Champion

    Hi,

    You need to create a QStyledItemDelegate, overload the createEditor function and return a QLineEdit with e.g. a mask or a QRegExpValidator.

    Hope it helps



  • Hi SGaist,

    Thanks for your feedback. I have been able to display hex numbers in my tableView following your suggestion.

    However, I still have the following issues with entering data to my tableView:

    1. When I enter values equal or above 80000000 to my tableView cell, it displays 8 letter F's in front of the 80000000 (i.e. displays FFFFFFFF80000000).

    2. I set @ editor->setInputMask("HHHHHHHH"); @ and I need to type 8 characters before return key works. How can I fix this restriction and be able to type any number of characters up to 8 and press the return key.


  • Lifetime Qt Champion

    Then go for QRegExpValidator with something like

    @[A-F0-8]{0,8}@

    Or if you are on Qt 5, QRegularExpression



  • I have figured out the root cause to isseu #1. I used type "int" instead of "qulonglong" in one place in my code.

    When I used QRegExpValidator and [A-Fa-f0-9]{0,8} as you suggested and removed editor->setInputMask("HHHHHHHH"); my second issue was resolved.

    Thanks for your suggestion.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.