Results 1 to 4 of 4

Thread: QTreeWidgetItem Problem

Hybrid View

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

    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].

  2. #2
    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 ?

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

    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, 13:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 13:48
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22: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
  •  
Qt is a trademark of The Qt Company.