[Qt-interest] removing items QTreeWidget

Mystical Groovy mysticalgr at gmail.com
Tue Nov 3 21:01:39 CET 2009


Hey BRM and thanks for your reply, I've tried to store the current item into
a QTreeWidgetItem and then remove it from the list using

items.removeOne(treeWidgetItem) but didnt worked, the code compiled ok but
no item is removed when i click the remove button...

any other suggestions?
i dont understand why is that hard to remove a freaking item from a list...

2009/11/3 BRM <bm_witness at yahoo.com>

> Hint: When the user clicks the remove button, get the current selection and
> store it in another variable; then process that variable to do the actual
> remove.
> Also, if removing multiple items, sort the list by reverse index - highest
> index to lowest index - so you don't have to keep retrieving the list of
> selected items.
>
> Ben
>
> P.S.  By doing the above you'll also make your code far more debuggable
> since you'll now have variables you control that you can monitor to see what
> is being done - for example, you'll be able to spot the index values and
> whether or not it's even returning a valid index (it might not be) or if
> you're
> using a function wrong. I know it's a stylistic thing - but believe me, it
> really helps to have code that supports debugging instead of code that looks
> smart and short; you'll save yourself a lot of time in the long run. Just 2
> cents.
>
> ------------------------------
> *From:* Mystical Groovy <mysticalgr at gmail.com>
> *To:* qt-interest at trolltech.com
> *Sent:* Tue, November 3, 2009 12:29:48 PM
> *Subject:* Re: [Qt-interest] removing items QTreeWidget
>
> Anyone?
> Ill have to manage this one way or another, so please help :)
>
> 2009/11/2 Mystical Groovy <mysticalgr at gmail.com>
>
>>  Hey all,
>>
>> Im using QTreeWidget and a QList to display some create items from
>> user-input text.
>>
>> code below:
>>  Qt Code:
>>
>>
>>
>>
>>
>> QList<QTreeWidgetItem *> items;
>>
>> items.append(new QTreeWidgetItem <http://doc.trolltech.com/latest/QTreeWidgetItem.html>((QTreeWidget <http://doc.trolltech.com/latest/QTreeWidget.html>*)0,QStringList <http://doc.trolltech.com/latest/QStringList.html>(QString <http://doc.trolltech.com/latest/QString.html>(repoText))));//repoText = user-input text
>>
>>
>> repoList->insertTopLevelItems(0, items); //repoList= my QTreeWidget
>>
>>  now i have a remove button that when the user clicks it i want it to
>> remove the currently selected item.
>>
>> using the following code, items from the QTreeWidget are removed but not
>> the one ive clicked! ("!?!WTF...)
>>  Qt Code:
>>
>>
>>
>> int x = items.indexOf(repoList->currentItem());
>>
>>     repoList->takeTopLevelItem(x);
>>
>> Ive also tried the following with no luck:
>>  Qt Code:
>>
>>
>>
>>
>>
>>
>>
>> //with the following 2, the program compiles fine but nothing happens when i choose an item and click the remove button.
>>
>>     repoList->selectedItems().removeAt(x);
>>     repoList->currentItem()->takeChild(x);
>>
>>
>>
>> //i get a bunch of errors using the following one...
>>     repoList->selectedItems().removeAll(repoList->currentItem()->text(0));
>>
>>  anyways, thank you for your time, and please help :_)
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091103/bb0e84f9/attachment.html 


More information about the Qt-interest-old mailing list