Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top