c++ - empty row in QTreeWidget after item delete -


I created a QTreeWidget with the QT Creator and it is full.

When I remove an item from the tree, an empty line goes down to the end of the tree

Image:

Code> Zero Gpa :: on_removeButton_clicked () {QTreeWidgetItem * items = new QTreeWidgetItem (UI-> TreeWidget); Item = ui- & gt; Tree; Widget-> Current itam (); QString txt = item- & gt; Text (0); // search vector for item int i; For (i = 0; i & lt; vec.size (); i ++) if (vec.at (i) -> getCode () == txt) break; Vec.erase (vec.begin () + i); Int index = ui- & gt; Treeview-& gt; Index offtake item (item); UI- & gt; TreeWidget-> TakeTopLevelItem (index); }

If you are removing a top level item, Method:

  QTreeWidgetItem * QTreeWidget :: takeTopLevelItem (integer index)   

Otherwise, you are removing a child if you are at the top level An indicator should match item (or a child of high-level items) and use:

  QTreeWidgetItem * QTreeWidgetItem :: takeChild (integer index)   

< Strong> Edit (After posting OP your code Or> were) I believe that the problem lies here:

  QTreeWidgetItem * item = new QTreeWidgetItem (UI- & gt; treeWidget); Item = ui- & gt; Tree; Widget-> Current itam ();   

You are assigning a new QTreeWidgetItem, and then you specify that pointer to the point you want to remove. So basically, you're building a new empty object and you remove the old one. Try changing your code:

  QTreeWidgetItem * items; Item = ui- & gt; Tree; Widget-> Current itam ();    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -