4

I use a QTreeWidget that shows a file listing so that a user can copy files to a directory. I want to disallow the user to copy the files to the same directory. Thus, I want to disable just one line in my QTreeWidget so that it is not selectable. I tried to use the setDisable(bool) method of the QTreeWidgetItem object but the problem is it disables the whole subtree.

How to get just one line disabled in a QTreeWidget ?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Tangui
  • 3,626
  • 2
  • 26
  • 28
  • Not sure it will work, but have you tried disabling the one you want and then enable all the sub-items? – Anthony Oct 18 '10 at 12:25

2 Answers2

2

I would try to disable the Qt::ItemIsDropEnabled flag with QTreeWidgetItem::setFlags, ie.e. setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled)

I did not test this.

hmuelner
  • 8,093
  • 1
  • 28
  • 39
  • I would try this with unsetting the ItemIsSelectable flag. This would leave it (and presumably the rest of the tree) enabled, but not allow the user to select that particular item. – Caleb Huitt - cjhuitt Oct 18 '10 at 16:26
  • 1
    Thanks for your answers, but it doesn't work neither. At best, the line is not highlighted, but you are still on it (a dotted border is visible). – Tangui Oct 19 '10 at 02:46
-3

If you want to disallow copying files into a directory, make directory read-only.

chmod(dir, 0555) will do directory - dir readonly, you can chmod() in

--Cheers

Koteswara sarma
  • 434
  • 3
  • 7