Results 1 to 4 of 4

Thread: adding elements to QTreeWidget column 2

  1. #1
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default adding elements to QTreeWidget column 2

    I have a 2 columns QTreeWidget.
    Only first column is populated. How can I populate the second column?

    thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: adding elements to QTreeWidget column 2

    The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.

    Tree widget items are used to hold rows of information for tree widgets. Rows usually contain several columns of data, each of which can contain a text label and an icon.

    The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget class.

    Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree).

    For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:

    Qt Code:
    1. QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
    2. cities->setText(0, tr("Cities"));
    3. QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities);
    4. osloItem->setText(0, tr("Oslo")); //Column 1
    5. osloItem->setText(1, tr("Yes")); //Column 2
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: adding elements to QTreeWidget column 2

    Quote Originally Posted by Santosh Reddy View Post
    For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:

    Qt Code:
    1. QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
    2. cities->setText(0, tr("Cities"));
    3. QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities);
    4. osloItem->setText(0, tr("Oslo")); //Column 1
    5. osloItem->setText(1, tr("Yes")); //Column 2
    To copy to clipboard, switch view to plain text mode 
    Ok thanks,
    now suppose to have column 3 not populated, and you want to populate column 3 for "Oslo".
    how can you do?

    thanks

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: adding elements to QTreeWidget column 2

    a QTreeWidgetItem represents the a complete row, it will have all the columns in it, you just can select the column of your interest, no need create them. This is a convenience class.

    Do you mean to have custom Widget for Column 3, then you need to subclass QTreeWidgetItem.

    When subclassing QTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.
    If want ot have custom widget in column 3, then sub-class QTreeWidgetItem

    When subclassing QTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.

Similar Threads

  1. List all elements of a QTreeWidget from top to bottom
    By ricardosf in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2010, 02:46
  2. not able move across elements in QTreeWidget
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2010, 19:35
  3. Adding elements with QXmlStreamWriter
    By hazardpeter in forum Newbie
    Replies: 4
    Last Post: 22nd August 2009, 12:45
  4. Adding elements to a QListView
    By Arreis in forum Newbie
    Replies: 4
    Last Post: 30th June 2009, 06:56
  5. QAbstractProxyModel: adding a virtual column
    By ultim8 in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2008, 17:10

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.