def __init__(self, viewport): super().__init__() self.viewport = viewport self.moduleName = "QViewportHeader" self.setContentsMargins(0, 0, 0, 0) boxLayout = QBoxLayout(QBoxLayout.LeftToRight) boxLayout.setContentsMargins(0, 0, 0, 0) boxLayout.setSpacing(0) self.setLayout(boxLayout) titleBtn = QToolButton() titleBtn.setAutoRaise(True) titleBtn.setToolButtonStyle(Qt.ToolButtonTextOnly) titleBtn.setPopupMode(QToolButton.InstantPopup) self.titleBtn = titleBtn pivotSnapping = QToolButton() pivotSnapping.setToolTip("Pivot Snapping") pivotSnapping.setAutoRaise(True) pivotSnapping.setCheckable(True) self.pivotSnapping = pivotSnapping boxLayout.addWidget(titleBtn, 1) boxLayout.addStretch(1)
def createLayout(self): #build layout for the dialog box importButton = QPushButton("Import", self) importButton.clicked.connect(self.importSVG) saveButton = QPushButton("Save", self) saveButton.clicked.connect(self.saveEvent) self.symbolName = QLineEdit(self) self.symbolName.setPlaceholderText("Enter Symbol Name") symbolNameLabel = QLabel("Symbol Name") symbolNameLabel.setBuddy(self.symbolName) self.symbolClass = QLineEdit(self) self.symbolClass.setPlaceholderText("Enter Symbol Class Name") symbolClassLabel = QLabel("Symbol Class Name") symbolClassLabel.setBuddy(self.symbolClass) self.symbolCategory = QLineEdit(self) self.symbolCategory.setPlaceholderText("Enter Symbol Category") symbolCategoryLabel = QLabel("Symbol Category") symbolCategoryLabel.setBuddy(self.symbolCategory) addGripItem = QPushButton("Add Grip Item", self) addGripItem.clicked.connect(self.addGrip) addLineGripItem = QPushButton("Add Line Grip Item", self) addLineGripItem.clicked.connect(self.addLineGrip) self.painter = QGraphicsScene() view = QGraphicsView(self.painter) layout = QGridLayout(self) subLayout = QBoxLayout(QBoxLayout.LeftToRight) subLayout.addWidget(importButton) subLayout.addWidget(saveButton) subLayout.addStretch(1) layout.addLayout(subLayout, 0, 0, 1, -1) subLayout2 = QBoxLayout(QBoxLayout.LeftToRight) subLayout2.addWidget(view, stretch=1) subLayout3 = QBoxLayout(QBoxLayout.TopToBottom) subLayout3.addWidget(symbolNameLabel) subLayout3.addWidget(self.symbolName) subLayout3.addWidget(symbolClassLabel) subLayout3.addWidget(self.symbolClass) subLayout3.addWidget(symbolCategoryLabel) subLayout3.addWidget(self.symbolCategory) subLayout3.addStretch(1) subLayout3.addWidget(addGripItem) subLayout3.addWidget(addLineGripItem) subLayout2.addLayout(subLayout3) layout.addLayout(subLayout2, 1, 0, -1, -1) self.setLayout(layout)
def add_settings(self): main_layout = QBoxLayout(QBoxLayout.TopToBottom) for box_title, settings in self.gui_settings.items(): box = QGroupBox(box_title, self) box_layout = QBoxLayout(QBoxLayout.TopToBottom) for name, text in settings.items(): control, layout = self.get_setting_control(name, text) box_layout.addLayout(layout) self.controls[name] = control box.setLayout(box_layout) main_layout.addWidget(box) if main_layout.count() > 2: self.settingsLayout.addItem(main_layout) main_layout = QBoxLayout(QBoxLayout.TopToBottom) main_layout.addStretch() self.settingsLayout.addItem(main_layout)
def _layout_control(self): self._control_group = QGroupBox('Control') self._control_lineEdit = QLineEdit() self._control_lineEdit.setDisabled(True) self._control_btn_start = QPushButton('Start', self) self._control_btn_start.clicked.connect(self.click_start) self._control_btn_stop = QPushButton('Stop', self) self._control_btn_stop.clicked.connect(self.click_stop) self._control_btn_stop.setDisabled(True) topBox = QBoxLayout(QBoxLayout.LeftToRight) topBox.addWidget(self._control_lineEdit) self.set_progress_text('[+] Load printers connected currently') pList = get_printer_list() if not pList: self.set_progress_text('[+] Connected nothing') else: self._printer_btn = {} for p in pList: self.set_progress_text(p.__str__()) if p['name'] in TARGET_PRINTER_NAMES: self._printer_btn[p['name']] = QPushButton(p['name'], self) self._printer_btn[p['name']].clicked.connect( getattr(self, "click_pbtn_" + p['name'])) topBox.addWidget(self._printer_btn[p['name']]) self.set_progress_text('[+] Create meaningful printer buttons') bottomBox = QBoxLayout(QBoxLayout.LeftToRight) bottomBox.addStretch(1) bottomBox.addWidget(self._control_btn_start) bottomBox.addWidget(self._control_btn_stop) bottomBox.addStretch(1) box = QBoxLayout(QBoxLayout.TopToBottom) box.addLayout(topBox) box.addLayout(bottomBox) self._control_group.setLayout(box)
def lay_out( layout_object: QBoxLayout, *items_or_items_with_stretch_factors: typing.Union[QWidget, QLayout, typing.Tuple[QWidget, int], typing.Tuple[QLayout, int], typing.Tuple[None, int]]): for item in items_or_items_with_stretch_factors: if isinstance(item, tuple): item, stretch = item else: item, stretch = item, 0 if isinstance(item, QLayout): layout_object.addLayout(item, stretch) elif isinstance(item, QWidget): layout_object.addWidget(item, stretch) elif item is None: layout_object.addStretch(stretch) else: raise TypeError(f'Unexpected type: {type(item)!r}')
def rebuildTeamHotkeys(self, teamHotkeysHLayout: QBoxLayout, tabWidget: QTabWidget): """ Delete all child widgets """ while teamHotkeysHLayout.count(): child = teamHotkeysHLayout.takeAt(0) if child.widget(): child.widget().deleteLater() bar = tabWidget.tabBar() hotkeyRDict = {v: k for k, v in self.hotkeyDict.items()} # LOG.debug("tab count="+str(bar.count())) for i in range(0, bar.count()): # An apparent bug causes the tabButton (a label) to not have a text attrubite; # so, use the whatsThis attribute instead. callsign = bar.tabWhatsThis(i) hotkey = hotkeyRDict.get(callsign, "") label = QLabel(hotkey) label.setFixedWidth(bar.tabRect(i).width()) label.setStyleSheet("border:0px solid black;margin:0px;font-style:italic;font-size:14px;background-image:url(:/radiolog_ui/blank-computer-key.png) 0 0 30 30;") label.setAlignment(Qt.AlignCenter) teamHotkeysHLayout.addWidget(label) teamHotkeysHLayout.addStretch()
def append_trailing_spacer_to_layout(layout: QBoxLayout): layout.addStretch()
class SlidersGroup(QGroupBox): valueChanged = pyqtSignal(int) def __init__(self, commandBox, parent=None): super(SlidersGroup, self).__init__("", parent) self.slidersLayout = QBoxLayout(QBoxLayout.LeftToRight) self.commandBox = commandBox self.sliders = [] # self.spinBoxes = [] self.labels = [] if len(screen_data) == 1: self.slidersLayout.addStretch() for i, (name, value) in enumerate(screen_data): self.createBrightnessCtrl(name, value, i) if len(screen_data) > 1: self.createBrightnessCtrl("All", 100, None) self.sliders[-1].valueChanged.connect(self.setAllValues) self.setLayout(self.slidersLayout) self.refreshCurrentValues() def createBrightnessCtrl(self, name, value, i): sl = QSlider(Qt.Vertical) sl.setFocusPolicy(Qt.StrongFocus) sl.setTickPosition(QSlider.TicksBothSides) sl.setTickInterval(10) sl.setSingleStep(1) sl.setMinimum(5) sl.setMaximum(100) sl.setValue(value) sb = QSpinBox() sb.setRange(5, 100) sb.setSingleStep(10) sb.setValue(value) sl.valueChanged.connect(sb.setValue) sb.valueChanged.connect(sl.setValue) if i != None: sl.valueChanged.connect(self.setValuePartial(i)) sb.valueChanged.connect(self.setValuePartial(i)) boxLayout = QBoxLayout(QBoxLayout.LeftToRight) lbl = QLabel(name) boxLayout.addWidget(lbl) boxLayout.addWidget(sb) boxLayout.addWidget(sl) self.slidersLayout.addLayout(boxLayout) # stretch is between (label, spinner, slider) groups if i != None: self.slidersLayout.addStretch() self.sliders.append(sl) # self.spinBoxes.append(sl) self.labels.append(lbl) def setValue(self, i, value): global screen_data screen_data[i] = (screen_data[i][0], value) self.refreshCommandBox() def setValuePartial(self, i): s = self.setValue return lambda value: s(i, value) def setAllValues(self, value): for sl in self.sliders: sl.setValue(value) def refreshCurrentValues(self): for i in range(len(screen_data)): lbl = self.labels[i] name, value = screen_data[i] if i == primary and len(screen_data) > 1: name += " (primary) " lbl.setText(name + " (" + str(value) + ")") self.refreshCommandBox() def refreshCommandBox(self): self.commandBox.document().setPlainText("# apply changes") for command in get_apply_commands(): self.commandBox.appendPlainText(command)