Results 1 to 4 of 4

Thread: QTreeWidgetItem Problem

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default QTreeWidgetItem Problem

    Friends

    I have a QTreeWidget and some items in there QTreeWidgetItems.
    Is there anyway to insert an item at the top of the item list.When Iam trying to insert an item at the top by

    insertTopLevelItem(0, item);

    The item is coming below the existing item...Its not going to the top of the list. How could I force an item to appear at the top of all the items ..

    Any help would be appreaciated.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidgetItem Problem

    did you see notice in description of QTreeWidget::insertTopLevelItem?
    If the item has already been inserted somewhere else it wont be inserted.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: QTreeWidgetItem Problem

    so how could I insert an item at the top and all other items should be increased by one and they should be rearranged ?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeWidgetItem Problem

    something like this?
    Qt Code:
    1. QTreeWidget *treeWidget = new QTreeWidget();
    2. treeWidget->setColumnCount(1);
    3. QList<QTreeWidgetItem *> items;
    4. for (int i = 0; i < 10; ++i) {
    5. QTreeWidgetItem *parent = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)));
    6. for (int j = 0; j < 10; ++j)
    7. new QTreeWidgetItem(parent, QStringList(QString("item: %1").arg(i)));
    8. items.append(parent);
    9. }
    10. treeWidget->insertTopLevelItems(0, items);
    11.  
    12. QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(-1)));
    13. for (int i = 0; i < 10; ++i) {
    14. QTreeWidgetItem *parent = new QTreeWidgetItem(item, QStringList(QString("item: %1").arg(i)));
    15. for (int j = 0; j < 10; ++j)
    16. new QTreeWidgetItem(parent, QStringList(QString("item: %1").arg(i)));
    17. items.append(parent);
    18. }
    19. treeWidget->insertTopLevelItem(0, item);
    20.  
    21. QVBoxLayout *vbl = new QVBoxLayout(this);
    22. vbl->addWidget(treeWidget);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.