Results 1 to 2 of 2

Thread: How can I restore itemWidget after taking it from treeWidget?

  1. #1
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default How can I restore itemWidget after taking it from treeWidget?

    Hi all,
    I'm using Qt4.2.2 and I have following problem related to QTreeWidget.
    I want to add item widget and for doing that I'm using setItemWidget() method.
    Then I need to move any item to another row. The code looks like this:

    QTreeWidget* tree = new QTreeWidget;
    QStringList l;
    l << "Hello";
    QTreeWidgetItem* it = new QTreeWidgetItem(tree, l);
    tree->setItemWidget(it, 1, new QComboBox(tree));
    /*
    ......
    */
    int c = tree->indexOfTopLevelItem(it);
    QComboBox* combo = qobject_cast<QComboBox*>(tree->itemWidget(it, 1));
    tree->takeTopLevelItem(it);
    tree->insertTopLevelItem(it, c+1);

    1)
    tree->setItemWidget(it, 1, combo);

    2)
    tree->setItemWidget(it, 1, new QComboBox);

    In 1) case, item widget disappears but in 2) case not. But I don't need for new widget. I want to add to item that widget which originally added to it. How can I do it.

    P.S. I have tried to do this setIndexWidget() method, but it doesn't help me too.

    Please help me.

    Thanks in advance.

    --davit

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I restore itemWidget after taking it from treeWidget?

    Have you tried passing another widget (or null) to the "old" cell to change/remove the item widget?

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.