def set_menu(self): for option in self.options: button = QAction(QIcon(option["icon"]), option["text"], self.parent()) button.setToolTip(option['tooltip']) button.parm = str(option["parm"]) button.callback = option["callback"] button.triggered.connect(self._call_callback_for_parm) self.menu.addAction(button) self.setMenu(self.menu)
def __init__(self, parent, text, options): super().__init__(parent) self.options = options self.text = text self.value = None self.setStyleSheet("color:white;") self.h_layout = QHBoxLayout() self.label = QLabel(self.text) self.combo_box = QPushButton('', self) self.combo_box.clicked.connect(self.combo_box.showMenu) self.menu = QtWidgets.QMenu(self) for header in self.options: button = QAction(header["name"], self) button.parm = header["name"] button.valid = header['split_by'] if header['split_by']: button.triggered.connect(self.change_combo_box) else: button.setIcon(QIcon(icon.UNAVAILABLE_I())) self.menu.addAction(button) self.combo_box.setMenu(self.menu) def set_default(): for action in self.menu.actions(): if action.valid: action.trigger() return set_default() self.h_layout.addWidget(self.label) self.h_layout.addWidget(self.combo_box) self.setLayout(self.h_layout)