[Qt-interest] removing items QTreeWidget

BRM bm_witness at yahoo.com
Tue Nov 3 18:58:39 CET 2009


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((QTreeWidget*)0,QStringList(QString(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/3924632d/attachment.html 


More information about the Qt-interest-old mailing list