Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to force a tableView to only display and accept hex numbers?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lhb007
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lhb007
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then go for QRegExpValidator with something like

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

          Or if you are on Qt 5, QRegularExpression

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lhb007
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved