def __init__(self, cti, delegate, parent=None): """ See the AbstractCtiEditor for more info on the parameters """ super(ChoiceCtiEditor, self).__init__(cti, delegate, parent=parent) comboBox = QtWidgets.QComboBox() comboBox.setEditable(cti.editable) comboBox.setInsertPolicy(cti.insertPolicy) setWidgetSizePolicy(comboBox, QtWidgets.QSizePolicy.Expanding, None) if cti.completer is not NOT_SPECIFIED: comboBox.setCompleter(cti.completer if cti.completer else None) comboBox.addItems(cti._displayValues) # Store the configValue in the combo box, although it's not currently used. for idx, configValue in enumerate(cti._configValues): comboBox.setItemData(idx, configValue, role=Qt.UserRole) comboBox.activated.connect(self.comboBoxActivated) comboBox.model().rowsInserted.connect(self.comboBoxRowsInserted) self.comboBox = self.addSubEditor(comboBox, isFocusProxy=True) # Install an eventFilter on the QListView that pops-up and contains all the items. # This allows the user to remove items by pressing the delete key in the list. self._comboboxListView = comboBox.view() self._comboboxListView.installEventFilter(self)
def _createComboBoxes(self, row): """ Creates a combo box for each of the fullAxisNames """ tree = self.tree model = self.tree.model() self._setColumnCountForContents() for col, _ in enumerate(self._axisNames, self.COL_FIRST_COMBO): logger.debug("Adding combobox at ({}, {})".format(row, col)) comboBox = QtWidgets.QComboBox() comboBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents) comboBox.activated.connect(self._comboBoxActivated) self._comboBoxes.append(comboBox) #editor = LabeledWidget(QtWidgets.QLabel(comboLabel), comboBox) tree.setIndexWidget(model.index(row, col), comboBox)
def main(): import sys app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QWidget() layout = QtWidgets.QVBoxLayout(window) if 0: if 1: window.setStyleSheet(""" QLabel { background-color: #FF9900; } """) else: window.setStyleSheet(""" QLabel { margin: 5px; border: 0px solid blue; background-color: #FF9900; padding: 0px; } """) label0 = QtWidgets.QLabel('my great line edit') label1 = QtWidgets.QLabel('edit') label2 = QtWidgets.QLabel('combo') all_labels = [label0, label1, label2] for lbl in all_labels: _setLabelProps(lbl) harmonizeLabelsTextWidth(all_labels) maxWidth = labelsMaxTextWidth([label0, label1, label2]) print("\mmaxWidth: {}".format(maxWidth)) tableView = QtWidgets.QTableView() layout.addWidget(tableView) model = QtGui.QStandardItemModel(3, 2) tableView.setModel(model) tableView.horizontalHeader().resizeSection(0, 200) tableView.horizontalHeader().resizeSection(1, 300) layoutSpacing = 0 editor0 = QtWidgets.QSpinBox() editor0.setValue(5) editor0.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) lw0 = LabeledWidget(label0, editor0, layoutSpacing=layoutSpacing) model.setData(model.index(0, 0), "A small") tableView.setIndexWidget(model.index(0, 1), lw0) editor1 = QtWidgets.QSpinBox() editor1.setValue(7) editor1.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) lw1 = LabeledWidget(label1, editor1, layoutSpacing=layoutSpacing) model.setData(model.index(1, 0), "A SMALL seasoned curly") tableView.setIndexWidget(model.index(1, 1), lw1) comboBox = QtWidgets.QComboBox() comboBox.addItems([ "Half diet coke", "Half regular coke", "Junior western bacon cheese" ]) lw2 = LabeledWidget(label2, comboBox, layoutSpacing=layoutSpacing) model.setData(model.index(2, 0), "What else?") tableView.setIndexWidget(model.index(2, 1), lw2) window.resize(550, 400) window.show() window.raise_() sys.exit(app.exec_())