View Full Version : QTreeWidgetItem swap or move up one level problem

24th September 2006, 18:32
I have build a tool to manage xml tree categories on infinite level but now...
i like insert a function to move up item or swap item ...

My question... exist a similar function from QTreeWidgetItem to make this?
I can access each QTreeWidgetItem by nummer


void Tree_Category::AppendItemTree()
if (Maus_Select_Active) { /* active QTreeWidgetItem */
/*int sotto_totale = Niagara_Actual->childCount();*/
/*qDebug() << "### found 0 " << sotto_totale;*/
bool ok;
QString SetNewName = QInputDialog::getText(this, tr("New Item append here"),tr("Name:"), QLineEdit::Normal,"", &ok);
if (ok && !SetNewName.isEmpty()) {
QTreeWidgetItem *newsub = new QTreeWidgetItem(Niagara_Actual);
watposition++; /* numeration */
QString xput = QString("[%1] %2").arg(QString::number(watposition),SetNewName);
PutOptionNow(newsub); /* set various option and put to other class qlist */
} else {
QMessageBox::warning( this, tr( "Error" ), tr( "Select on item please!"));

24th September 2006, 18:52
QTreeWidget doesn't provide such functionality out of the box. This thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-qtablewidget-move-row-3386.html) contains code example for swapping 2 rows in a QTableWidget. It should be rather straigthforward to adjust for QTreeWidget.

24th September 2006, 19:34
i found a solution .....

by loading QTreeWidget and update load all text to a QStringList ....
by move or swap select destination from a combobox QStringList

search the destination text findname .....

QList<QTreeWidgetItem*> items = niagara->findItems(findname, Qt::MatchRecursive | Qt::MatchExactly , 0);

if (items.count() == 1) {
/* clone source and destination and update source to "findname" ....*/

so i can swap item to all level :-) .....