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. Drag and Drop hidden columns workaround in treeview?
Forum Updated to NodeBB v4.3 + New Features

Drag and Drop hidden columns workaround in treeview?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 447 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.
  • alomA Offline
    alomA Offline
    alom
    wrote on last edited by
    #1

    I have a treeview that is using a proxy to hide one of the columns. The tree view has an drag and drop mode set to InternalMove. When I drag and Drop an item the hidden row's item becomes null.

    This looks to be a known issue with the standardItemModel and the devs dont want to change it:
    https://bugreports.qt.io/browse/QTBUG-30242

    They did give a workaround as to override the selectedIndexes() in the view

    class MyTreeView : public QTreeView
    {
    protected:
        QModelIndexList selectedIndexes() const
        {
            return selectionModel()->selectedIndexes();
        }
    };
    

    However in my view it does not help the hidden column issue at all

    class HiddenTreeView(QtWidgets.QTreeView):
        def __init__(self, parent):
            super(HiddenTreeView, self).__init__(parent)
            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.setDragEnabled(False)
            self.setDragDropOverwriteMode(False)
            self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
            self.setAlternatingRowColors(True)
            self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
            self.setSortingEnabled(True)
            self.header().setStretchLastSection(True)
            self.header().setMinimumSectionSize(30)
    
        def selectedIndexes(self):
            return self.selectionModel().selectedIndexes()
    

    Am I missing something here? The self.selectionModel().selectedIndexes() still only returns the visible only items.

    Cheers

    1 Reply Last reply
    0
    • alomA Offline
      alomA Offline
      alom
      wrote on last edited by
      #2

      The purpose of the internal move drag and drop is to allow the user to create any hierarchy they need. I've allowed a custom context menu to create a parent on any item.

      The hidden column was used in conjunction with a qdatawidgetmapper to manage a filter property in the proxy model. For now I can get around the issue by putting that data in a custom UserRole and making a itemDelegate for the qdatawidgetmapper. I was just hoping to not have to make the delegate to reduce the complexly of the code, but it seems to work atm.

      I'd still like to know what the devs where referring too with their provided example.

      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