我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtWidgets.QGroupBox()。
def __init__(self, parent=None): super().__init__(parent) self.wizard = self.parent() options = ['ecoinvent homepage', 'local 7z-archive', 'local directory with ecospold2 files'] self.radio_buttons = [QtWidgets.QRadioButton(o) for o in options] self.option_box = QtWidgets.QGroupBox('Choose type of database import') box_layout = QtWidgets.QVBoxLayout() for i, button in enumerate(self.radio_buttons): box_layout.addWidget(button) if i == 0: button.setChecked(True) self.option_box.setLayout(box_layout) self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.option_box) self.setLayout(self.layout)
def createTopLeftGroupBox(self): self.topLeftGroupBox = QGroupBox("Temperature Sensor") tempLabel = QLabel('Temperature: ') self.tempValLabel = QLabel('NULL') plotButton = QPushButton("Show Plot") plotButton.clicked.connect(self.tempPlot) saveDataButton = QPushButton('Save Data File') saveDataButton.clicked.connect(self.savefile) vbox1 = QVBoxLayout() vbox1.addWidget(tempLabel) vbox1.addWidget(self.tempValLabel) vbox2 = QVBoxLayout() vbox2.addWidget(plotButton) vbox2.addWidget(saveDataButton) layout = QHBoxLayout() layout.addLayout(vbox1) layout.addLayout(vbox2) layout.addStretch(1) self.topLeftGroupBox.setLayout(layout)
def createTopRightGroupBox(self): self.topRightGroupBox = QGroupBox('Heater') heatLabel = QLabel('Target Temperature(C):') heatEntry = QLineEdit() heatEntry.textChanged[str].connect(self.tempOnChanged) heatEntry.setText('41') self.heatButton = QPushButton('Heater ON') self.heatButton.clicked.connect(self.heaterPower) hbox1 = QHBoxLayout() hbox1.addWidget(heatLabel) hbox1.addWidget(heatEntry) hbox2 = QHBoxLayout() hbox2.addWidget(self.heatButton) layout = QVBoxLayout() layout.addLayout(hbox1) layout.addLayout(hbox2) layout.addStretch(1) self.topRightGroupBox.setLayout(layout)
def createBottomLeftGroupBox(self): self.bottomLeftGroupBox = QGroupBox('Sensor Options') captureBtn = QPushButton('Capture Data') captureBtn.clicked.connect(self.captureDataThread) setNormOptionsBtn = QPushButton('Set Normal Options') setNormOptionsBtn.clicked.connect(self.normalSettings) setDarkOptionsBtn = QPushButton('Set Low Light Options') setDarkOptionsBtn.clicked.connect(self.darkSettings) saveBtn = QPushButton('Save Data') saveBtn.clicked.connect(self.saveData) layout = QVBoxLayout() layout.addWidget(captureBtn) layout.addWidget(setNormOptionsBtn) layout.addWidget(setDarkOptionsBtn) layout.addWidget(saveBtn) layout.addStretch(1) self.bottomLeftGroupBox.setLayout(layout)
def createHorizontalLayout(self): self.horizontalGroupBox = QGroupBox("What is your favorite color?") layout = QHBoxLayout() buttonBlue = QPushButton('Blue', self) buttonBlue.clicked.connect(self.on_click) layout.addWidget(buttonBlue) buttonRed = QPushButton('Red', self) buttonRed.clicked.connect(self.on_click) layout.addWidget(buttonRed) buttonGreen = QPushButton('Green', self) buttonGreen.clicked.connect(self.on_click) layout.addWidget(buttonGreen) self.horizontalGroupBox.setLayout(layout)
def createGridLayout(self): self.horizontalGroupBox = QGroupBox("Grid") layout = QGridLayout() layout.setColumnStretch(1, 4) layout.setColumnStretch(2, 4) layout.addWidget(QPushButton('1'),0,0) layout.addWidget(QPushButton('2'),0,1) layout.addWidget(QPushButton('3'),0,2) layout.addWidget(QPushButton('4'),1,0) layout.addWidget(QPushButton('5'),1,1) layout.addWidget(QPushButton('6'),1,2) layout.addWidget(QPushButton('7'),2,0) layout.addWidget(QPushButton('8'),2,1) layout.addWidget(QPushButton('9'),2,2) self.horizontalGroupBox.setLayout(layout)
def setLang(self, langName): uiList_lang_read = self.memoData['lang'][langName] for ui_name in uiList_lang_read: ui_element = self.uiList[ui_name] if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox if uiList_lang_read[ui_name] != "": ui_element.setText(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]: # uiType: QMenu, QGroupBox if uiList_lang_read[ui_name] != "": ui_element.setTitle(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() if uiList_lang_read[ui_name] != "": tabNameList = uiList_lang_read[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != "": ui_element.setTabText(i,tabNameList[i]) elif type(ui_element) == str: # uiType: string for msg if uiList_lang_read[ui_name] != "": self.uiList[ui_name] = uiList_lang_read[ui_name]
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) # ?? ?? self.gb = QGroupBox(self.tr("Serial")) self.cb_port = QComboBox() self.cb_baud_rate = QComboBox() self.cb_data_bits = QComboBox() self.cb_flow_control = QComboBox() self.cb_parity = QComboBox() self.cb_stop_bits = QComboBox() # ??? ???? ?? # ??? ??? ?? ? ?? self.serial = QSerialPort() self.serial_info = QSerialPortInfo() self.serial_read_thread = SerialReadThread(self.serial) self.serial_read_thread.received_data.connect(lambda v: self.received_data.emit(v)) self.serial_read_thread.start() self.init_widget()
def setupUi(self, Form): Form.setObjectName("Form") sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.groupBox = QtWidgets.QGroupBox(Form) self.groupBox.setObjectName("groupBox") self.formLayout = QtWidgets.QFormLayout(self.groupBox) self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.formLayout.setObjectName("formLayout") self.nc_label = QtWidgets.QLabel(self.groupBox) self.nc_label.setObjectName("nc_label") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.nc_label) self.nc_spin = QtWidgets.QSpinBox(self.groupBox) self.nc_spin.setObjectName("nc_spin") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.nc_spin) self.verticalLayout.addWidget(self.groupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Form): Form.setObjectName("Form") self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.groupBox = QtWidgets.QGroupBox(Form) self.groupBox.setObjectName("groupBox") self.gridLayout = QtWidgets.QGridLayout(self.groupBox) self.gridLayout.setObjectName("gridLayout") self.renameDataLabel = QtWidgets.QLabel(self.groupBox) self.renameDataLabel.setObjectName("renameDataLabel") self.gridLayout.addWidget(self.renameDataLabel, 0, 0, 1, 1) self.renameDataComboBox = QtWidgets.QComboBox(self.groupBox) self.renameDataComboBox.setObjectName("renameDataComboBox") self.gridLayout.addWidget(self.renameDataComboBox, 0, 1, 1, 1) self.toDataLabel = QtWidgets.QLabel(self.groupBox) self.toDataLabel.setObjectName("toDataLabel") self.gridLayout.addWidget(self.toDataLabel, 0, 2, 1, 1) self.toDataLineEdit = QtWidgets.QLineEdit(self.groupBox) self.toDataLineEdit.setObjectName("toDataLineEdit") self.gridLayout.addWidget(self.toDataLineEdit, 0, 3, 1, 1) self.verticalLayout.addWidget(self.groupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Form): Form.setObjectName("Form") sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.formGroupBox = QtWidgets.QGroupBox(Form) self.formGroupBox.setObjectName("formGroupBox") self.formLayout = QtWidgets.QFormLayout(self.formGroupBox) self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.formLayout.setObjectName("formLayout") self.chooseDataToDerivLabel = QtWidgets.QLabel(self.formGroupBox) self.chooseDataToDerivLabel.setObjectName("chooseDataToDerivLabel") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.chooseDataToDerivLabel) self.chooseDataToDerivComboBox = QtWidgets.QComboBox(self.formGroupBox) self.chooseDataToDerivComboBox.setObjectName("chooseDataToDerivComboBox") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.chooseDataToDerivComboBox) self.verticalLayout.addWidget(self.formGroupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Form): Form.setObjectName("Form") sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.groupBox = QtWidgets.QGroupBox(Form) self.groupBox.setObjectName("groupBox") self.formLayout = QtWidgets.QFormLayout(self.groupBox) self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.formLayout.setObjectName("formLayout") self.fitInterceptLabel = QtWidgets.QLabel(self.groupBox) self.fitInterceptLabel.setObjectName("fitInterceptLabel") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.fitInterceptLabel) self.fitInterceptCheckBox = QtWidgets.QCheckBox(self.groupBox) self.fitInterceptCheckBox.setChecked(True) self.fitInterceptCheckBox.setObjectName("fitInterceptCheckBox") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.fitInterceptCheckBox) self.verticalLayout.addWidget(self.groupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Form): Form.setObjectName("Form") sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.formGroupBox = QtWidgets.QGroupBox(Form) self.formGroupBox.setObjectName("formGroupBox") self.formLayout = QtWidgets.QFormLayout(self.formGroupBox) self.formLayout.setObjectName("formLayout") self.numOfComponentsLabel = QtWidgets.QLabel(self.formGroupBox) self.numOfComponentsLabel.setObjectName("numOfComponentsLabel") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.numOfComponentsLabel) self.numOfComponentsLineEdit = QtWidgets.QLineEdit(self.formGroupBox) self.numOfComponentsLineEdit.setObjectName("numOfComponentsLineEdit") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.numOfComponentsLineEdit) self.verticalLayout.addWidget(self.formGroupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, Form): Form.setObjectName("Form") self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.groupbox = QtWidgets.QGroupBox(Form) self.groupbox.setObjectName("groupbox") self.formLayout_2 = QtWidgets.QFormLayout(self.groupbox) self.formLayout_2.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) self.formLayout_2.setObjectName("formLayout_2") self.windowSizeLabel = QtWidgets.QLabel(self.groupbox) self.windowSizeLabel.setObjectName("windowSizeLabel") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.windowSizeLabel) self.windowSizeSpinBox = QtWidgets.QSpinBox(self.groupbox) self.windowSizeSpinBox.setObjectName("windowSizeSpinBox") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.windowSizeSpinBox) self.verticalLayout.addWidget(self.groupbox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def setupUi(self, pmi_control_panel): pmi_control_panel.setObjectName("pmi_control_panel") pmi_control_panel.resize(623, 200) pmi_control_panel.setMaximumSize(QtCore.QSize(16777215, 200)) self.horizontalLayout = QtWidgets.QHBoxLayout(pmi_control_panel) self.horizontalLayout.setObjectName("horizontalLayout") self.groupBox_2 = QtWidgets.QGroupBox(pmi_control_panel) self.groupBox_2.setObjectName("groupBox_2") self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.groupBox_2) self.verticalLayout_3.setObjectName("verticalLayout_3") self.filteredList = QtWidgets.QListWidget(self.groupBox_2) self.filteredList.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.filteredList.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) self.filteredList.setObjectName("filteredList") self.verticalLayout_3.addWidget(self.filteredList) self.resetButton = QtWidgets.QPushButton(self.groupBox_2) self.resetButton.setObjectName("resetButton") self.verticalLayout_3.addWidget(self.resetButton) self.horizontalLayout.addWidget(self.groupBox_2) self.retranslateUi(pmi_control_panel) QtCore.QMetaObject.connectSlotsByName(pmi_control_panel)
def room_box(self, chat_list): groupBox = QGroupBox("??? ??") vbox = QVBoxLayout() """ try: for i, children in enumerate(vbox.findChildren(QPushButton)): children.deleteLater() for x in range(int(len(chat_list) / 2)): vbox.addWidget(QPushButton(chat_list[x * 2 + 1])) print(QPushButton(chat_list[x * 2 + 1])) except Exception as e: print(e) """ a = QPushButton('hi') vbox.addWidget(a) a.clicked.connect(self.make_chat) groupBox.setLayout(vbox) return groupBox
def createBottomLeftGroupBox(self): self.bottomLeftGroupBox = QGroupBox('Pump') self.pumpPowerButton = QPushButton('Power ON') self.pumpPowerButton.clicked.connect(self.pumpPower) pumpEntry = QLineEdit() pumpEntry.textChanged[str].connect(self.pumpOnChanged) pumpValChangeButton = QPushButton('Submit') pumpValChangeButton.clicked.connect(self.pumppowerchange) layout = QVBoxLayout() layout.addWidget(self.pumpPowerButton) layout.addWidget(pumpEntry) layout.addWidget(pumpValChangeButton) layout.addStretch(1) self.bottomLeftGroupBox.setLayout(layout)
def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox('Status') self.tempSensorLbl = QLabel('Temp. Sensor OFF') self.pumpLbl = QLabel('Pump OFF') self.heatLbl = QLabel('Heater OFF') layout = QVBoxLayout() layout.addWidget(self.tempSensorLbl) layout.addWidget(self.pumpLbl) layout.addWidget(self.heatLbl) layout.addStretch(1) self.bottomRightGroupBox.setLayout(layout)
def createTopGroupBox(self): self.topGroupBox = QGroupBox('Integration Time') self.it2_4ms = QRadioButton() self.it2_4ms.setText('2.4ms') self.it2_4ms.toggled.connect(lambda: self.itstate(self.it2_4ms)) self.it24ms = QRadioButton() self.it24ms.setText('24ms') self.it24ms.toggled.connect(lambda: self.itstate(self.it24ms)) self.it50ms = QRadioButton() self.it50ms.setText('50ms') self.it50ms.toggled.connect(lambda: self.itstate(self.it50ms)) self.it101ms = QRadioButton() self.it101ms.setText('101ms') self.it101ms.toggled.connect(lambda: self.itstate(self.it101ms)) self.it154ms = QRadioButton() self.it154ms.setText('154ms') self.it154ms.toggled.connect(lambda: self.itstate(self.it154ms)) self.it700ms = QRadioButton() self.it700ms.setText('700ms') self.it700ms.toggled.connect(lambda: self.itstate(self.it700ms)) self.it2_4ms.setChecked(True) layout = QHBoxLayout() layout.addWidget(self.it2_4ms) layout.addWidget(self.it24ms) layout.addWidget(self.it50ms) layout.addWidget(self.it101ms) layout.addWidget(self.it154ms) layout.addWidget(self.it700ms) layout.addStretch(1) self.topGroupBox.setLayout(layout)
def createMidGroupBox(self): self.midGroupBox = QGroupBox('Gain') self.gain1 = QRadioButton() self.gain1.setText('1X') self.gain1.toggled.connect(lambda: self.gnstate(self.gain1)) self.gain4 = QRadioButton() self.gain4.setText('4X') self.gain4.toggled.connect(lambda: self.gnstate(self.gain4)) self.gain16 = QRadioButton() self.gain16.setText('16X') self.gain16.toggled.connect(lambda: self.gnstate(self.gain16)) self.gain60 = QRadioButton() self.gain60.setText('60X') self.gain60.toggled.connect(lambda: self.gnstate(self.gain60)) self.gain1.setChecked(True) layout = QHBoxLayout() layout.addWidget(self.gain1) layout.addWidget(self.gain4) layout.addWidget(self.gain16) layout.addWidget(self.gain60) layout.addStretch(1) self.midGroupBox.setLayout(layout)
def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox('Sensor Data') self.intensityLbl = QLabel('Not Taken') layout = QHBoxLayout() layout.addWidget(self.intensityLbl) layout.addStretch(1) self.bottomRightGroupBox.setLayout(layout)
def addGroup( self, label ): self.group = QtWidgets.QGroupBox( label ) self.v_layout.addWidget( self.group ) self.grid = QtWidgets.QGridLayout() self.grid.setColumnStretch( 1, 1 ) self.group.setLayout( self.grid )
def __init__(self, parent=None): super().__init__(parent) self.setSubTitle(self.tr("<h2>Save Your Settings</h2>")) vlayout = QVBoxLayout(self) label = QLabel(self) label.setWordWrap(True) label.setText(self.tr("<p>You have successfully finished all steps. Here's a summary of the settings you want to apply. \ Click <strong>Apply Settings</strong> to save them now. You are now ready to enjoy KaOS!</p>")) vlayout.addWidget(label) vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred)) groupBox = QGroupBox() groupBox.setTitle(self.tr("The following settings will be applied")) groupBox.setMinimumHeight(350) groupLayout = QHBoxLayout(groupBox) self.labelSummary = QLabel() self.labelSummary.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) groupLayout.addWidget( self.labelSummary) self.labelSummary2 = QLabel() self.labelSummary2.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) groupLayout.addWidget( self.labelSummary2) vlayout.addWidget(groupBox) vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred)) self.summary = {} self.parent().summaryVisible.connect(self.summaryWrite)
def __init__(self, category_name): super().__init__(category_name) self.layout = QtWidgets.QVBoxLayout() self.setLayout(self.layout) self.spacer = None cat = api.categories.get_unique(name=category_name) if not cat: return self.setStyleSheet( "QGroupBox{{background-color: {}}}".format(cat['color']) )
def finalise(self): """ Finalise Add a spacer at the bottom of the QGroupBox layout """ policy = QtWidgets.QSizePolicy.Expanding self.spacer = QtWidgets.QSpacerItem(0, 0, vPolicy=policy) self.layout.addItem(self.spacer)
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(911, 688) self.horizontalLayout_4 = QtWidgets.QHBoxLayout(Form) self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.splitter = QtWidgets.QSplitter(Form) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName("splitter") self.editorBox = QtWidgets.QGroupBox(self.splitter) self.editorBox.setObjectName("editorBox") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.editorBox) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.verticalLayout_2 = QtWidgets.QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") self.plainTextEdit = QtWidgets.QPlainTextEdit(self.editorBox) self.plainTextEdit.setObjectName("plainTextEdit") self.verticalLayout_2.addWidget(self.plainTextEdit) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.clearButton = QtWidgets.QPushButton(self.editorBox) self.clearButton.setObjectName("clearButton") self.horizontalLayout.addWidget(self.clearButton) self.previewButton = QtWidgets.QPushButton(self.editorBox) self.previewButton.setObjectName("previewButton") self.horizontalLayout.addWidget(self.previewButton) self.verticalLayout_2.addLayout(self.horizontalLayout) self.horizontalLayout_2.addLayout(self.verticalLayout_2) self.previewerBox = QtWidgets.QGroupBox(self.splitter) self.previewerBox.setObjectName("previewerBox") self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.previewerBox) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.webView = QtWebKitWidgets.QWebView(self.previewerBox) self.webView.setUrl(QtCore.QUrl("about:blank")) self.webView.setObjectName("webView") self.horizontalLayout_3.addWidget(self.webView) self.horizontalLayout_4.addWidget(self.splitter) self.retranslateUi(Form) self.clearButton.clicked.connect(self.plainTextEdit.clear) QtCore.QMetaObject.connectSlotsByName(Form)
def setLang(self, langName): lang_data = self.memoData['lang'][langName] for ui_name in lang_data.keys(): if ui_name in self.uiList.keys() and lang_data[ui_name] != '': ui_element = self.uiList[ui_name] # '' means no translation availdanle in that data file if isinstance(ui_element, (QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox) ): # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox ui_element.setText(lang_data[ui_name]) elif isinstance(ui_element, (QtWidgets.QGroupBox, QtWidgets.QMenu) ): # uiType: QMenu, QGroupBox ui_element.setTitle(lang_data[ui_name]) elif isinstance(ui_element, QtWidgets.QTabWidget): # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = lang_data[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != '': ui_element.setTabText(i,tabNameList[i]) elif isinstance(ui_element, QtWidgets.QComboBox): # uiType: QComboBox itemCnt = ui_element.count() itemNameList = lang_data[ui_name].split(';') ui_element.clear() ui_element.addItems(itemNameList) elif isinstance(ui_element, QtWidgets.QTreeWidget): # uiType: QTreeWidget labelCnt = ui_element.headerItem().columnCount() labelList = lang_data[ui_name].split(';') ui_element.setHeaderLabels(labelList) elif isinstance(ui_element, QtWidgets.QTableWidget): # uiType: QTableWidget colCnt = ui_element.columnCount() headerList = lang_data[ui_name].split(';') cur_table.setHorizontalHeaderLabels( headerList ) elif isinstance(ui_element, (str, unicode) ): # uiType: string for msg self.uiList[ui_name] = lang_data[ui_name]
def quickGrpUI(self, ui_name, ui_label, ui_layout): self.uiList[ui_name] = QtWidgets.QGroupBox(ui_label) if isinstance(ui_layout, QtWidgets.QLayout): self.uiList[ui_name].setLayout(ui_layout) elif isinstance(ui_layout, str): ui_layout = self.quickLayout(ui_name+"_layout", ui_layout) self.uiList[ui_name].setLayout(ui_layout) return [self.uiList[ui_name], ui_layout]
def loadLang(self): self.quickMenu(['language_menu;&Language']) cur_menu = self.uiList['language_menu'] self.quickMenuAction('langDefault_atnLang', 'Default','','langDefault.png', cur_menu) cur_menu.addSeparator() self.uiList['langDefault_atnLang'].triggered.connect(partial(self.setLang,'default')) # store default language self.memoData['lang']={} self.memoData['lang']['default']={} for ui_name in self.uiList: ui_element = self.uiList[ui_name] if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox self.memoData['lang']['default'][ui_name] = str(ui_element.text()) elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]: # uiType: QMenu, QGroupBox self.memoData['lang']['default'][ui_name] = str(ui_element.title()) elif type(ui_element) in [ QtWidgets.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() tabNameList = [] for i in range(tabCnt): tabNameList.append(str(ui_element.tabText(i))) self.memoData['lang']['default'][ui_name]=';'.join(tabNameList) elif type(ui_element) == str: # uiType: string for msg self.memoData['lang']['default'][ui_name] = self.uiList[ui_name] # try load other language lang_path = os.path.dirname(self.location) # better in packed than(os.path.abspath(__file__)) baseName = os.path.splitext( os.path.basename(self.location) )[0] for fileName in os.listdir(lang_path): if fileName.startswith(baseName+"_lang_"): langName = fileName.replace(baseName+"_lang_","").split('.')[0].replace(" ","") self.memoData['lang'][ langName ] = self.readRawFile( os.path.join(lang_path,fileName) ) self.quickMenuAction(langName+'_atnLang', langName.upper(),'',langName + '.png', cur_menu) self.uiList[langName+'_atnLang'].triggered.connect(partial(self.setLang,langName)) # if no language file detected, add export default language option if len(self.memoData['lang']) == 1: self.quickMenuAction('langExport_atnLang', 'Export Default Language','','langExport.png', cur_menu) self.uiList['langExport_atnLang'].triggered.connect(self.exportLang)
def qui(self, ui_list_string, parentObject_string='', opt=''): # pre-defined user short name syntax type_dict = { 'vbox': 'QVBoxLayout','hbox':'QHBoxLayout','grid':'QGridLayout', 'form':'QFormLayout', 'split': 'QSplitter', 'grp':'QGroupBox', 'tab':'QTabWidget', 'btn':'QPushButton', 'btnMsg':'QPushButton', 'label':'QLabel', 'input':'QLineEdit', 'check':'QCheckBox', 'choice':'QComboBox', 'txtEdit': 'LNTextEdit', 'txt': 'QTextEdit', 'tree': 'QTreeWidget', 'table': 'QTableWidget', 'space': 'QSpacerItem', } # get ui_list, creation or existing ui object ui_list = [x.strip() for x in ui_list_string.split('|')] for i in range(len(ui_list)): if ui_list[i] in self.uiList: # - exisiting object ui_list[i] = self.uiList[ui_list[i]] else: # - string creation: # get part info partInfo = ui_list[i].split(';',1) uiName = partInfo[0].split('@')[0] uiType = uiName.rsplit('_',1)[-1] if uiType in type_dict: uiType = type_dict[uiType] # set quickUI string format ui_list[i] = partInfo[0]+';'+uiType if len(partInfo)==1: # give empty button and label a place holder name if uiType in ('btn', 'btnMsg', 'QPushButton','label', 'QLabel'): ui_list[i] = partInfo[0]+';'+uiType + ';'+uiName elif len(partInfo)==2: ui_list[i]=ui_list[i]+";"+partInfo[1] # get parentObject or exisiting object parentObject = parentObject_string if parentObject in self.uiList: parentObject = self.uiList[parentObject] # process quickUI self.quickUI(ui_list, parentObject, opt)
def __init__(self): super().__init__() self.show() self.raise_() self.showNormal() self.updating_gui_bool = False # self.rest_actions_qbg = QtWidgets.QButtonGroup() vbox_l2 = QtWidgets.QVBoxLayout() self.setLayout(vbox_l2) hbox_l3 = QtWidgets.QHBoxLayout() vbox_l2.addStretch(1) vbox_l2.addLayout(hbox_l3) vbox_l2.addStretch(1) # Main area self.main_area_qgb = QtWidgets.QGroupBox("Rest Actions") hbox_l3.addWidget(self.main_area_qgb) self.actions_list_vbox_l4 = QtWidgets.QVBoxLayout() self.main_area_qgb.setLayout(self.actions_list_vbox_l4) walking_mindfully_qll = QtWidgets.QLabel("Please move and walk mindfully when leaving the computer") walking_mindfully_qll.setFont(mc_global.get_font_medium()) vbox_l2.addWidget(walking_mindfully_qll) vbox_l2.addStretch(1) buttons_hbox_l3 = QtWidgets.QHBoxLayout() vbox_l2.addLayout(buttons_hbox_l3) self.close_qpb = QtWidgets.QPushButton("Close") buttons_hbox_l3.addWidget(self.close_qpb) self.close_qpb.clicked.connect(self.on_close_clicked) self.close_and_breathe_qpb = QtWidgets.QPushButton("Close and Breathe") buttons_hbox_l3.addWidget(self.close_and_breathe_qpb) self.close_and_breathe_qpb.clicked.connect(self.on_close_and_breathe_clicked) self.setup_rest_action_list()
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(462, 431) self.list_images = QtWidgets.QListView(MainWindow) self.list_images.setGeometry(QtCore.QRect(10, 10, 180, 371)) self.list_images.setObjectName("list_images") self.b_delete = QtWidgets.QPushButton(MainWindow) self.b_delete.setGeometry(QtCore.QRect(10, 390, 180, 30)) self.b_delete.setObjectName("b_delete") self.captured_image = QtWidgets.QLabel(MainWindow) self.captured_image.setGeometry(QtCore.QRect(200, 10, 250, 100)) self.captured_image.setFrameShape(QtWidgets.QFrame.Box) self.captured_image.setText("") self.captured_image.setObjectName("captured_image") self.b_save = QtWidgets.QPushButton(MainWindow) self.b_save.setGeometry(QtCore.QRect(360, 390, 95, 30)) self.b_save.setObjectName("b_save") self.groupBox = QtWidgets.QGroupBox(MainWindow) self.groupBox.setGeometry(QtCore.QRect(200, 180, 141, 151)) self.groupBox.setObjectName("groupBox") self.b_noIndicator = QtWidgets.QPushButton(self.groupBox) self.b_noIndicator.setGeometry(QtCore.QRect(10, 30, 121, 30)) self.b_noIndicator.setObjectName("b_noIndicator") self.b_leftIndicator = QtWidgets.QPushButton(self.groupBox) self.b_leftIndicator.setGeometry(QtCore.QRect(10, 70, 121, 30)) self.b_leftIndicator.setObjectName("b_leftIndicator") self.b_rightIndicator = QtWidgets.QPushButton(self.groupBox) self.b_rightIndicator.setGeometry(QtCore.QRect(10, 110, 121, 30)) self.b_rightIndicator.setObjectName("b_rightIndicator") self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.setWindowTitle("RadioButton") # ??? ?? ?? ?? grp_1 = QGroupBox("Group 1") grp_2 = QGroupBox("Group 2") rb_1 = QRadioButton("RadioButton 1") rb_2 = QRadioButton("RadioButton 2") rb_3 = QRadioButton("RadioButton 3") rb_4 = QRadioButton("RadioButton 4") rb_5 = QRadioButton("RadioButton 5") # ???? ?? ? Form Widget? ?? base_layout = QBoxLayout(QBoxLayout.TopToBottom, self) grp_1_layout = QBoxLayout(QBoxLayout.TopToBottom) grp_2_layout = QBoxLayout(QBoxLayout.TopToBottom) grp_1.setLayout(grp_1_layout) grp_2.setLayout(grp_2_layout) grp_1_layout.addWidget(rb_1) grp_1_layout.addWidget(rb_2) grp_1_layout.addWidget(rb_3) grp_2_layout.addWidget(rb_4) grp_2_layout.addWidget(rb_5) base_layout.addWidget(grp_1) base_layout.addWidget(grp_2) self.setLayout(base_layout)