c++qtsignals-slotsqtreewidget

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


Solution

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