Results 1 to 4 of 4

Thread: Looking for examples of subclassing a QTreeView

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    2
    Qt products
    Platforms
    Unix/X11

    Default Looking for examples of subclassing a QTreeView

    I'm looking for an example of subclassing, and extending a view widget. Bonus points if it is in pyqt4, but I can follow C examples.

    I have a working data model (currently subclassed from qstandarditemmodel) that has both a tree like structure and a table like structure. IE, most items can be placed into column 1 with some hierarchy of parenting. These items all have vertical header information. However, some items should be grouped as multiple columns in a single row-- in this case the items have horizontal header information.

    I've dug around the internet and bugged my workmates; while there are plenty of examples of subclassing data models, I have yet to find an example or tutorial for subclassing a view widget.

    This is what I'd like to do:

    My first choice for displaying all this would be to add a vertical header to qtreeview. I've reimplemented qstandarditemmodel.headerData() in my data model to return an appropriate vertical header information for an item of arbitrary depth in column 1, however when I apply this to a free-standing qheaderview, it seems to think it needs to display only the invisibleRoot.childCount() number of items (ie, it doesn't count the number of items available if fully expanded). I haven't a clue how to intercept that count so I could show/hide header information as the tree expands and collapse. Nor do I have a clue how to make actually add the vertical headerView into the treeview subclass, rather than tacking it on as an external part of the layout.

    Okay, so that is the kind of stuff that I'd like to be able to do. Are there any examples of View subclassing out there that might give me some guidance?

    Much appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Looking for examples of subclassing a QTreeView

    There's a very nice example of subclassing a view:
    http://doc.qt.nokia.com/4.7/itemviews-chart.html

    But I would first try if it is possible to use a delegate.
    You also might want to find out if you can just put another treeview inside an index, that would make it a lot easier to implement.

  3. The following user says thank you to tbscope for this useful post:

    kgimpelson (24th February 2011)

  4. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Looking for examples of subclassing a QTreeView

    You've luck. The book Advanced Qt Programming has a chaper about this issue and that chaper is available as sample (click "Sample Content")

  5. The following user says thank you to nightghost for this useful post:

    kgimpelson (24th February 2011)

  6. #4
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: Looking for examples of subclassing a QTreeView

    Thanks all-- I've already got a delegate managing the various appearances and editors for my different items. I think the example and the book excerpt will be very helpful; indeed it sounds like customizing a view is what I want for changing the "bigger picture."

Similar Threads

  1. Subclassing QGraphicsItemGroup
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 08:41
  2. Subclassing QFontDialog
    By fsoltanshahi in forum Qt Programming
    Replies: 0
    Last Post: 23rd October 2008, 17:29
  3. Subclassing QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 11
    Last Post: 27th August 2007, 20:36
  4. Subclassing QScrollView
    By sumsin in forum Qt Programming
    Replies: 13
    Last Post: 16th March 2006, 15:20
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 15:06

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.