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. How to display a model data in 2 views in different format, say in binary and hexadecimal?
Qt 6.11 is out! See what's new in the release blog

How to display a model data in 2 views in different format, say in binary and hexadecimal?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.6k 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.
  • J Offline
    J Offline
    jj8431
    wrote on last edited by
    #1

    Hi I'm new to both GUI programming and Qt, just having a question and it has confused me for days.

    I need to display a model in 2 views, but in different format, in details, I have a 2 dimensional array of unsigned char, and want to display them in 2 table, one in binary format, and the other in hexadecimal.

    The model is derived from the QAbstractTableModel, and I'm using 2 QTableView to display it.

    I know I can let the model to output a QString in binary or hexadecimal format but that doesn't meet my requirement to share the same model within 2 views. So I just let the data() function to return a unsigned char directly.

    I guess a delegate is the right way to get the data rendered properly for each view? but I couldn't find a document about this, the delegate documents are all about editing data with widgets or graphic displays.

    I noticed there is a function called displayText() in QStyledItemDelegate, and I tried it and it works (derived 2 new delegates from it and overrided the displayText() functions) . But this function doesn't exist in QItemDelegate, according to the class reference, QStyledItemDelegate only comes to existance after Qt 4.4, so I guess there must be some other way to do it, in other words I might use the wrong approach.

    Could anyone give me some advice on this? Thanks

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Well you can create two proxy models, one for hex and one for bin. "qabstractproxymodel":http://qt-project.org/doc/qt-4.8/qabstractproxymodel.html
      "example":http://qt-project.org/doc/qt-5.0/qtwidgets/itemviews-customsortfiltermodel.html - this is a simple example for creating custom proxy model. In your case you need reimplement data().

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

        Hi,

        You can also manage to do it with only one delegate that you would configure. What version of Qt are you using ?

        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
        • J Offline
          J Offline
          jj8431
          wrote on last edited by
          #4

          Thank you all guys.
          Yep I agree a proxy model is another way to do that.
          I'm using Qt 4.6.2

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            I actually think a delegate is a nicer option here.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jj8431
              wrote on last edited by
              #6

              I still got the question, if you want to use delegate, is the displayText() function in QStyledItemDelegate the only way to go? What if you used a QItemDelegate ?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                It really depends on your precise requirements. You can even do the complete rendering of the item yourself if you want. I'd base my delegate of QStyledItemDelegate if I had a choice, but if you base of QItemDelegate I'd simply reimplement drawDisplay().

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jj8431
                  wrote on last edited by
                  #8

                  Thank you Andre

                  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