QTreeWidget:禁用一行但不禁用子树

发布于 2024-09-28 02:30:42 字数 188 浏览 0 评论 0原文

我使用 QTreeWidget 显示文件列表,以便用户可以将文件复制到目录。 我想禁止用户将文件复制到同一目录。 因此,我想仅禁用 QTreeWidget 中的一行,使其不可选择。我尝试使用 QTreeWidgetItem 对象的 setDisable(bool) 方法,但问题是它禁用了整个子树。

如何在 QTreeWidget 中仅禁用一行?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木落 2024-10-05 02:30:42

我会尝试使用 QTreeWidgetItem::setFlags 禁用 Qt::ItemIsDropEnabled 标志,
即setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled)

我没有测试这个。

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.

ゞ花落谁相伴 2024-10-05 02:30:42

如果您想禁止将文件复制到目录中,请将目录设置为只读。

chmod(dir, 0555) 将执行目录 - dir 只读,您可以在

--Cheers中 chmod()

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文