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. Boolean Display in QTableView [Solved]

Boolean Display in QTableView [Solved]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.3k Views
  • 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.
  • K Offline
    K Offline
    Kaptain Karl
    wrote on 6 May 2013, 21:05 last edited by
    #1

    I'm using a QTableView to display data in a QSqlRelationalTableModel from two related database tables. One of the tables contains a boolean field. I'd like this to display the word "True" or "False" rather than 1 or 0. The RDBMS is MySQL which stores booleans as tiny integers.

    I know I could get around this by altering the database to use a string field rather than a boolean field and just store "true" and "false" but that seems wasteful.

    How would I go about this?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dkruger
      wrote on 6 May 2013, 22:25 last edited by
      #2

      I'm not sure what the recommended way would be, but I can think of two straight-forward ways off the top of my head.

      Create an inherited model and override the QAbstractItemModel::data() function. Have it return "True" or "False" for the Qt::DisplayRole of the column in question.

      Create a custom QItemDelegate for that column/table which renders the boolean field to "True" or "False". You can assign it with QAbstractItemView::setItemDelegateForColumn() or QAbstractItemView::setItemDelegate().

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 7 May 2013, 07:34 last edited by
        #3

        Hi and welcome to devnet,

        A third way would be to use a "QIdentityProxyModel":http://qt-project.org/doc/qt-4.8/qidentityproxymodel.html in a similar fashion as 1. suggested by dkruger

        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
        • K Offline
          K Offline
          Kaptain Karl
          wrote on 7 May 2013, 15:28 last edited by
          #4

          I went the QItemDelegate solution. Mostly because I could wrap my head around it the best. Thanks for the suggestions.
          Karl

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 May 2013, 07:08 last edited by
            #5

            You're welcome !

            Don't forget to update the thread's title to solved so other forum users will know that it's all good :)

            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

            4/5

            7 May 2013, 15:28

            • Login

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