简体   繁体   English

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

[英]QTreeWidget; Disabling ui Features when multiple Items are selected in QTree

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. 我是一名学生程序员,我正在使用Qt为工作构建GUI,我遇到了各种各样的问题。 In my main interface I have a QTreeWidget that holds data. 在我的主界面中,我有一个保存数据的QTreeWidget。 Also in this GUI I have the buttons Edit, copy, and delete which are already perspectively connected to functions. 同样在这个GUI中,我有按钮编辑,复制和删除,它们已经透视地连接到功能。 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. 我认为最好的方法(再次我是学生)将是某种类型的连接语句,但我一直在查看这个小部件的Qt文档,并且无法找到任何看起来正确的东西。 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. 如果我可以使用这个信号,请说清楚,因为我在这里打空了,因为我不知道从哪里开始将它与被选中的多个项目联系起来。

I don't think you can do it solely in QtDesigner, if that's what you're trying to do. 我不认为你只能在QtDesigner中做到这一点,如果那是你想要做的。 You could define you own slot to handle itemSelectionChanged signal. 您可以定义自己的插槽来处理itemSelectionChanged信号。 In that slot you can use selectedItems method of QTreeWidget to check the number of selected items and enable/disable buttons based on that. 在该插槽中,您可以使用QTreeWidget的selectedItems方法来检查所选项目的数量,并根据该项目启用/禁用按钮。

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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM