I am creating the GUI of a preprocessor to be able to solve flow problems, I need the items that are in the ListWidget to save the state of the checkbox that I want to select
Example of the behavior I require
Is this possible? If so, how would I achieve it?
I tried using the setData method, I wanted to save the state of each checkbox using an array with values of 0 and 1, so every time one of the items was selected, I expected the state to be saved as a value in the array, to later read it when the item is selected again and place the corresponding checkbox as checked.
self.bordesWindow.ui.listWidgetVarEsc.itemSelectionChanged.connect(self.settingCheckBoxStateBorde)
self.bordesWindow.ui.listWidgetVarEsc.itemClicked.connect(self.gettingCheckBoxStateValue)
def settingCheckBoxStateBorde(self):
self.arrayValuesCheckboxesBordes = np.zeros(3)
self.constDataBordeCheckboxState = Qt.ItemDataRole.UserRole
item = self.bordesWindow.ui.listWidgetVarEsc.currentItem()
item.setData(self.constDataBordeCheckboxState, self.arrayValuesCheckboxesBordes)
if self.bordesWindow.ui.checkBoxVariablesEscValor.isChecked():
item.data(self.constDataBordeCheckboxState)[0] = 1
elif self.bordesWindow.ui.checkBoxVariablesEscFlujo.isChecked():
item.data(self.constDataBordeCheckboxState)[1] = 1
elif self.bordesWindow.ui.checkBoxVariablesEscConveccion.isChecked():
item.data(self.constDataBordeCheckboxState)[2] = 1
def gettingCheckBoxStateValue(self):
item = self.bordesWindow.ui.listWidgetVarEsc.currentItem()
if item.data(self.constDataBordeCheckboxState)[0] == 1:
self.bordesWindow.ui.checkBoxVariablesEscValor.setChecked(True)
elif item.data(self.constDataBordeCheckboxState)[1] == 1:
self.bordesWindow.ui.checkBoxVariablesEscFlujo.setChecked(True)
elif item.data(self.constDataBordeCheckboxState)[2] == 1:
self.bordesWindow.ui.checkBoxVariablesEscConveccion.setChecked(True)
Aucun commentaire:
Enregistrer un commentaire