QTreeWidget;在 QTree 中选择多个项目时禁用 ui 功能

发布于 2024-12-29 22:46:56 字数 528 浏览 4 评论 0原文

我是一名学生程序员,我正在使用 Qt 构建 GUI 来工作,但我遇到了一些问题。在我的主界面中,我有一个保存数据的 QTreeWidget。此外,在此 GUI 中,我还有“编辑”、“复制”和“删除”按钮,这些按钮已经与功能透视连接。我希望在选择多个项目时禁用编辑按钮。这就是我遇到问题的地方。我认为做到这一点的最佳方法(我再次成为一名学生)将是某种类型的 connect 语句,但我一直在查看 此小部件的 Qt 文档 并且找不到任何看起来适合于此的内容。我希望有更有经验的人能够提供一些指导。

我想知道我是否应该/可以使用

void QTreeWidget::itemSelectionChanged () [signal]

如果我可以使用这个信号,请透露一些信息,因为我在这里遇到了空白,因为我不知道从哪里开始将它与选择的多个项目相关联。

I'm a student programmer and I am using Qt to build a GUI for work and I have ran into an issue of sorts. In my main interface I have a QTreeWidget that holds data. Also in this GUI I have the buttons Edit, copy, and delete which are already perspectively connected to functions. I would like the edit button to be disabled when multiple items are selected. Here is where I am having my issue. I assume that the best way to do this (once again I am a student) would be some type of connect statement but I have been looking through the Qt Documentation for this widget and cant find anything that seems right for this. I was hoping someone more experienced to be able to provide some direction with this.

I was wondering if I should/can use

void QTreeWidget::itemSelectionChanged () [signal]

If I could use this signal please shed some light because I'm hitting a blank here as I wouldn't know where to begin to relate it to multiple items being selected.

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

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

发布评论

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

评论(2

一张白纸 2025-01-05 22:46:56

是的,这是正确的信号。例如,这里是您问题的插槽的简单实现:

void disableItems() {

    QList<QTreeWidgetItem*> selection = treeWidget->selectedItems();
    if(selection.size() > 1) {

        //disable the gui items here

    } else { 

        //maybe reenable items otherwise
    }
}

Yea this is the right signal. For example here is trivial implementation of the slot for your question:

void disableItems() {

    QList<QTreeWidgetItem*> selection = treeWidget->selectedItems();
    if(selection.size() > 1) {

        //disable the gui items here

    } else { 

        //maybe reenable items otherwise
    }
}
勿挽旧人 2025-01-05 22:46:56

如果您想这样做,我认为您不能仅在 QtDesigner 中完成此操作。
您可以定义自己的插槽来处理 itemSelectionChanged 信号。在该插槽中,您可以使用 QTreeWidget 的 selectedItems 方法来检查所选项目的数量并根据该数量启用/禁用按钮。

I don't think you can do it solely in QtDesigner, if that's what you're trying to do.
You could define you own slot to handle itemSelectionChanged signal. In that slot you can use selectedItems method of QTreeWidget to check the number of selected items and enable/disable buttons based on that.

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