Results 1 to 5 of 5

Thread: How to "share" a QTreeWidget

  1. #1
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to "share" a QTreeWidget

    Hi.

    I'm working on a application that uses couple of windows, and couple of them uses the same QThreeWidget, my question is
    Is there a simple way to share the same qtreewidget (or only the information of item expands and selections) between different QDialogs?

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to "share" a QTreeWidget

    Use a QTreeView instead of a QTreeWidget. You can set the same instance of your model to multiple instances of QTreeView.
    See: http://qt-project.org/doc/qt-5.0/qtw...qtreeview.html

  3. #3
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to "share" a QTreeWidget

    OK.
    I read about QTreeView... and don't find any simple answer. What i need to do is make a tree trom data stored in table
    Qt Code:
    1. NAME | ParaneID | ID | Description
    2. foo | 0 | 1 | Some entry
    3. bar | 1 | 2 | another entry
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. name DESC
    2. |-> FOO Some entry
    3. |-> BAR another entry
    To copy to clipboard, switch view to plain text mode 

    I need to store in my model Name, description and ID. In QTreeWidget I create a item, setText (0,name); (1,ID); (2,desc) and add the item as root (if parent = 0) or as a child of different entry. How can I do it with QStandardItemModel? Only thing I found is an example where are entries with children having only one column... I need multiple columns in children.

  4. #4
    Join Date
    Oct 2011
    Posts
    51
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to "share" a QTreeWidget

    Sory for 2 posts in row but I don't know how edit last one...
    The thing I was missing is

    Qt Code:
    1. void QStandardItem::setChild(int row, int column, QStandardItem * item)
    To copy to clipboard, switch view to plain text mode 

    function

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to "share" a QTreeWidget

    QTreeWidgets are independent of each other with separate data and selections. A shared selection is only really sensible if the underlying data model is also shared.

    If you want the same data presented in three view then you should use QTreeView and a separate model. You can build a usable tree model with QStandardItemModel or write your own custom model.
    If you have three views sharing the same model and want the same current and selected items in each then point them all at the same QItemSelectionModel (i.e. share one).

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 22:46
  2. Replies: 3
    Last Post: 15th February 2010, 18:27
  3. QTreeWidget and keep "focus drawing" every time
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2008, 18:04
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

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.