Results 1 to 2 of 2

Thread: QAbstractItemModel with shared children (PyQt5, Python)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QAbstractItemModel with shared children (PyQt5, Python)

    I am not good enough at python to completely understand what you are doing, but what I think your code is doing is trying to create a tree that nests under columns other than column 0. QAbstractItemModel allows this, but QTreeView does not. Tree views only support nesting under the 0-th column of each row. I am also not sure if you are doing the right thing in the index() method. "row" is relative to the parent index (that is, row = n is the nth child of the parent), whereas "col" is relative to the columns in "row". In addition, you aren't returning an invalid QModelIndex for conditions where either "row" or "col" are not valid. With python's dynamic typing, I don't know what is being returned if the methods falls off the bottom. For example, for "Researcher" and the other single fields in your tree model, the row count is zero for those indices since they have no children. (Assuming you have drawn your tree schematically the way you intend for it to appear in the tree view).

    In addition, you must implement parent() correctly. By returning a null index, I don't think your code will work beyond displaying the topmost entry.

    Check out the Qt Simple Tree Model example. It's in C++, but mapping that to python should be straightforward.
    Last edited by d_stranz; 4th July 2018 at 00:51.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Python / PyQt5 MDI Window focus problem
    By apereira in forum Newbie
    Replies: 5
    Last Post: 21st September 2015, 23:29
  2. Access to shared map between parent - children
    By atomic in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2015, 22:24
  3. Replies: 0
    Last Post: 26th July 2015, 04:45
  4. Embedding PyQt4 into an Application running Python via Boost::Python
    By GreyHound in forum Installation and Deployment
    Replies: 1
    Last Post: 6th February 2012, 06:48
  5. Replies: 0
    Last Post: 8th April 2011, 20:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.