Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to display one row of data in 2 lines of a QTableView
Qt 6.12 LTS is out! See what's new in the release blog

How to display one row of data in 2 lines of a QTableView

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 888 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
    judethedude
    wrote on last edited by judethedude
    #1

    Hey everyone,
    I have a line of data in my SQLite3 database table that looks like this:
    9663e419-5b45-4c71-9e59-b5da6f464e3d-image.png
    Essentially it's right and left eye measurements.
    I'd like to view them in a table like this:
    2bfe6303-fc9a-45b6-b0f9-64d51334dcab-image.png
    Where the above would constitute one "row"

    Reading the documentation, this seems like a job for either QStyledItemDelegate, since its responsible for painting, or QTableView because it changes the indexes?

    Any tips or recommendations would be greatly appreciated, thanks all.

    EDIT: Or maybe I should subclass QAbstractTableModel:

        class TableModel(QtCore.QAbstractTableModel):
            def __init__(self, data):
                super().__init__()
                self._data = data
            def data(self, index, role):
                if index % 2 == 0:
                    # something here
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It would rather be option number 3: a proxy model that reassemble the data the way you want it.

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

      J 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        It would rather be option number 3: a proxy model that reassemble the data the way you want it.

        J Offline
        J Offline
        judethedude
        wrote on last edited by
        #3

        @SGaist do you think you could provide a small example? I'm kinda stuck here

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

          I just realized that it would make things complicated for nothing.

          Just implement a custom QStyledItemDelegate that draws the row entries the way you want to show them. Way simpler that rearranging the data as I suggested above.

          You would use a QListView so your delegate can simply pull the row data when painting.

          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

          • Login

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