I want to activate command link button if at least one element is checked in a treeview.
I tried this method but it is not working well :
def activate_launch_button(self):
model = self.scenarios.model()
checked_indexes = model.match(model.index(0, 0), QtCore.Qt.CheckStateRole,QtCore.Qt.Checked, -1,QtCore.Qt.MatchExactly | QtCore.Qt.MatchRecursive)
print checked_indexes
if checked_indexes != []:
self.launch_btn.setEnabled(True)
The problem with this method is the button is activated only after closing the window. I don't understand why. For caling this method I put it in two methods :
def show(self):
self.project.load()
if self.project.tranus_project:
self.tranus_folder.setText(self.project.tranus_project.path)
self.activate_launch_button()
self.launch_options_TRANUS()
super(OptionsTRANUSDialog, self).show()
def select_tranus_folder(self):
folder = QtGui.QFileDialog.getExistingDirectory(self, "Select directory")
if folder:
self.tranus_folder.setText(folder)
if not self.project.load_tranus_folder(folder):
self.tranus_folder.setText('')
self.reload_scenarios()
self.activate_launch_button()
I really want that the command link button should be activated when at least one element of treeview is checked and to be inactive if there is no element checked.
Thanks.
Aucun commentaire:
Enregistrer un commentaire