def __init__(self, elder): super().__init__() self.elder = elder self.layout = QGridLayout(self) self.settings = elder.settings self.listener = elder.listener checkbox = QCheckBox(self) checkbox.setText('Abbrevations enabled') checkbox.setChecked(self.settings.special['abbrevations_enabled']) checkbox.clicked.connect(self.checkbox_clicked) self.layout.addWidget(checkbox) abbrevations = QGroupBox(self) abbrevations.setTitle('Current Abbrevations') abbrevations_layout = QGridLayout(abbrevations) self.layout.addWidget(abbrevations) self.abbrevations_list = QListWidget(abbrevations) self.abbrevations_list.setSelectionMode(QListWidget.SingleSelection) for abbrevation, msg in self.settings.abbrevations.items(): # Add the new Item to QListWidget custom_widget = CustomListWidget(abbrevation, msg) item = QListWidgetItem(self.abbrevations_list) item.abbrevation = abbrevation item.msg_line_edit = custom_widget.msg_edit self.abbrevations_list.addItem(item) item.setSizeHint(custom_widget.minimumSizeHint()) self.abbrevations_list.setItemWidget(item, custom_widget) abbrevations_layout.addWidget(self.abbrevations_list, 0, 0, 1, 0) button = QPushButton(abbrevations) button.setText('Save') button.clicked.connect(self.update_abbrevations) abbrevations_layout.addWidget(button, 1, 0) button = QPushButton(abbrevations) button.setText('Add new') button.clicked.connect(self.add_item) abbrevations_layout.addWidget(button, 1, 1) button = QPushButton(abbrevations) button.setText('Remove selected') button.clicked.connect(self.remove_selected_item) abbrevations_layout.addWidget(button, 1, 2) self.layout.addWidget(abbrevations) self.setLayout(self.layout)
def add_item(self): dlg = AddItemDialog(self) if dlg.exec_(): abbrevation = dlg.abbrevation_edit.text() msg = dlg.msg_edit.text() # Add the new Item to QListWidget custom_widget = CustomListWidget(abbrevation, msg) item = QListWidgetItem(self.abbrevations_list) item.abbrevation = abbrevation item.msg_line_edit = custom_widget.msg_edit self.abbrevations_list.addItem(item) item.setSizeHint(custom_widget.minimumSizeHint()) self.abbrevations_list.setItemWidget(item, custom_widget)