Results 1 to 2 of 2

Thread: Programming technique with QTreeWidget or QListWidget

  1. #1
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Programming technique with QTreeWidget or QListWidget

    This is a question about programming practice. I am looking for opinions.

    Not infrequently I write applications where users interact with data through a list or tree widget of some sort. I've sort of stumbled upon two approaches to this:

    (1) I respond to events in the tree|list widget by figuring out the index of the widget item, and then modify the data structure (e.g. a QList) based on that widget.
    (2) I subclass QTreeWidgetItem (or QListWidgetItem), and include a pointer to the appropriate data structure in the new class. Then when an event occurs, I cast the pointer to QTreeWidgetItem to the subclass, and modify the data structure that way.

    At this point in my thinking, option #2 seems more elegant. I am open to suggestions.

    I should mention that while I'm aware of model/view programming, I've always had fairly simple applications, and whenever I've looked closely it looked like more trouble than it was worth (for my particular applications). If you think that model/view is definitely the way to go in any circumstance, I'd be interested to hear that.

    Thanks for your thoughts,
    Adam

  2. #2
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: Programming technique with QTreeWidget or QListWidget

    Just to make sure if I understand correctly, are you using QListWidget/QTreeWidget? (edit: well, I guess you are, now when I read the title of your post) These are convenience classes that you can use without subclassing QAbstractItemModel. They are, btw part of the Model/View framework so in this case, you are already using this approach.

    To me it sounds a bit like you are trying to re-implement existing functionality. Unless you have very specific requirements, I think that using built-in functionality as much as possible will give you a more flexible and reusable solution in the end.
    Last edited by helloworld; 31st January 2011 at 22:16.

Similar Threads

  1. set QListWidget/QTreeWidget icon size
    By rbp in forum Qt Programming
    Replies: 4
    Last Post: 14th October 2009, 02:05
  2. QListWidget/QTreeWidget Drag and Drop
    By hlvietlong in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2009, 18:09
  3. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  4. Drag from QTreeWidget and drop in QListWidget
    By WXNSNW in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 00:15
  5. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 06:50

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
  •  
Qt is a trademark of The Qt Company.