Results 1 to 2 of 2

Thread: Item insertion problem in QTreeWidget

  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Item insertion problem in QTreeWidget

    Hi Experts,
    I am inserting items in QTreewidget at top level using below function :
    InsertFile(QString filepath)
    {
    QTreeWidgetItem *NewItems=new QTreeWidgetItem(ui->treeWidget);
    NewItems->setText(0,filepath);
    ui->treeWidget->addTopLevelItem(NewItems);
    //ui->treeWidget->update();
    }
    After insert some item in Qtreewidget when i call this function another time then
    files are not inserted at top level of tree.
    File is inserted below the existing item and there is one row gap between them

    My problem is how remove the empty row.And Insert item continue.
    ![enter image description here][1]

    In Above image after inset two item when i insert item it insert at 3 index not at indesx 2.

    Untitled.jpg
    [1]: http://i.stack.imgur.com/6unvI.png
    If i delete item from Qtreewidget , item is remove but index is not free.
    QTreeWidgetItem *item;
    QList<QTreeWidgetItem *> list;
    list = ui->treeWidget->selectedItems();
    if(list.count())
    {
    ui->treeWidget->selectedItems().clear();
    item=list.takeFirst();
    delete item;
    }


    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: Item insertion problem in QTreeWidget

    Most probably InsertFile(QString filepath) is called with empty string.
    Qt Code:
    1. QList<QTreeWidgetItem *> list;
    2. list = ui->treeWidget->selectedItems();
    3. if(list.count())
    4. {
    5. ui->treeWidget->selectedItems().clear();
    6. item=list.takeFirst();
    7. delete ui->treeWidget->takeTopLevelItem(ui->treeWidget->indexOfTopLevelItem(item));
    8. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 4
    Last Post: 8th April 2011, 21:59
  2. [PYQT] QTreeWidget item delegate problem !
    By GMib in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2010, 22:26
  3. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 11:45
  4. Replies: 1
    Last Post: 20th January 2010, 09:38
  5. QTreeWidget, resizing item and widgets problem
    By The Storm in forum Qt Programming
    Replies: 15
    Last Post: 17th March 2008, 22:20

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.