Results 1 to 4 of 4

Thread: QTreeWidget or QTreeView ?

  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeWidget or QTreeView ?

    I'm designing a mainMenu form a bit like Qt Assistant and other GUI forms I've seen with a tree on the left and a stackedWidget on the right.
    I want to react to a tree item selection and flip the stackedWidget to the corresponding page. The cleanest and less-coding method I can think of is obtaining an integer of the selected menu item row so in my code I can simply code
    Qt Code:
    1. stackedWidget->setCurrentIndex(row)
    To copy to clipboard, switch view to plain text mode 
    I've experimented with both QTreeWidget or QTreeView and in both cases, I have to extract the parent and child and write a long if...else if...endif block to see what was selected. If there's no row() function available in either QTreeWidget or QTreeView I would probably add an invisible column that holds an int row.
    I also want to dynamically be able to insert or remove pages to the stackedWidget and update the tree at runtime via double-click and/or context menu on the tree.

    Which is more suitable...QTreeWidget or QTreeView ?
    All comments and criticism cheerfully accepted.
    Thanks,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget or QTreeView ?

    I don't think you need any long if statements for either QTreeWidget or QTreeView. The most straightforward way is to connect to currentItemChanged() or selectionModel()->currentChanged() signal (depending on the tree class you choose). Then you'll be able to use QModelIndex::row() to obtain the integer you want.

  3. #3
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeWidget or QTreeView ?

    Quote Originally Posted by wysota View Post
    Then you'll be able to use QModelIndex::row() to obtain the integer you want.
    This only returns the row for the parent. What's needed is this:
    Parent 1
    child 1
    child 2
    Parent 2
    child 1
    child 2
    so the last item should return 5, not 1.

  4. #4
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidget or QTreeView ?

    hi,

    QTreeView is meant to use with ItemModels i.e. when you have single data model and several views that shows it's contents in a different way or if you are viewing dbase contents(via QSql*Model which deals with dbase for you).
    QTreeWidget is in deed QTreeView with internal model & methods that deals with model in context of indexes.

    I think QTreeWidget is better for you, because you need single view, so providing model isn't necessary and QTreeWidget gives you some simplifications like mentioned row calculation.

Similar Threads

  1. how to add icons to QTreeWidget?
    By wei243 in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 08:34
  2. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  3. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  4. QTreeView / QTreeWidget
    By morty in forum Qt Programming
    Replies: 4
    Last Post: 8th October 2006, 00:40
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.