Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Getting data from QTreeView
Qt 6.11 is out! See what's new in the release blog

Getting data from QTreeView

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 2.4k 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.
  • M Offline
    M Offline
    Marcus Adamski
    wrote on last edited by
    #1

    Hello there,

    I'm using the QTreeView and pyside2. Headers were set up :

            model = QStandardItemModel(0, 2, treeview.parentWidget())
            model.setHeaderData(DUE_DATE, Qt.Horizontal, "Date Due")
            model.setHeaderData(TITLE, Qt.Horizontal, "To Do")
            model.setHeaderData(NOTES, Qt.Horizontal, "Notes")
    

    With DUE_DATE, TITLE and NOTE simple int constants. I added rows by :

            model.insertRow(0)
            model.setData(model.index(0, DUE_DATE), due_date.toString("d MMMM yy @ h:m ap"))
            model.setData(model.index(0, TITLE), title)
    

    NOTES column is hidden.

    I'd like to access the selected row data. I can retrieve the data in the first column with:

    model.data( treeview.currentIndex() )
    

    ... but for the selected row, how can I access the data in the other columns, on the same row (i.e. TITLE and NOTES)

    Alternatively, can someone point me to a basic pyside TreeView example using a QAbstractItemModel, to handle a list of objects (with header and rows, like the above) - as I feel this would be a better approach.

    thanks in advance

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

      Hi,

      You can use the QModelIndex.siblingAtColumn method.

      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
      • M Offline
        M Offline
        Marcus Adamski
        wrote on last edited by
        #3

        Ah thanks @SGaist didn't spot that in the documentation. Worked perfectly, thanks

        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