class MainUi(QWidget): def __init__(self): super(MainUi, self).__init__() self.setFixedSize(600,500) self.setWindowTitle("妹子图爬虫工具 version: 1.0.0 ") self.download_progressbar = QProgressBar() self.download_progressbar.setAlignment(QtCore.Qt.Alignment.AlignCenter)#文字居中 self.download_progressbar.setStyleSheet(".QProgressBar::chunk { background-color: red;}")#背景 self.download_progressbar.setValue(100) label01 = QLabel("下载URL:") label02 = QLabel("下载目录:") self.url_input = QLineEdit() self.url_input.setText("https://www.mzitu.com/221746") self.url_input.setContentsMargins(0,0,0,0) self.download_dir = QLineEdit() self.download_dir.setContentsMargins(0,0,0,0) self.start_btn = QPushButton("开始爬虫") self.start_btn.setFixedHeight(50) self.start_btn.setContentsMargins(0,0,0,0) inputlayout = QGridLayout() inputlayout.addWidget(label01, 0, 0) #第0行 0列 inputlayout.addWidget(label02, 1, 0) inputlayout.addWidget(self.url_input, 0, 1) inputlayout.addWidget(self.download_dir, 1, 1) inputlayout.addWidget(self.start_btn, 0, 2, 2,1,QtCore.Qt.Alignment.AlignRight) #起始行,起始列, 占行数,占列数 inputlayout.setColumnStretch(0, 1) #设置每一列比例 inputlayout.setColumnStretch(1, 10) inputlayout.setColumnStretch(2, 1) vlayout = QVBoxLayout() vlayout.addLayout(inputlayout) vlayout.addWidget(self.download_progressbar) self.frame = QFrame() self.frame.setFixedHeight(400) vlayout.addWidget(self.frame) vlayout.addStretch() inputlayout.setContentsMargins(0,0,0,0) vlayout01 = QVBoxLayout() self.frame.setLayout(vlayout01) self.qtablewidget = QTableWidget(1,3) self.qtablewidget.setHorizontalHeaderLabels(['目录','下载图片总数目', '删除']) vlayout01.addWidget(self.qtablewidget) self.qtablewidget.setColumnWidth(0, 358) # 将第0列的单元格,设置成300宽度 self.qtablewidget.setColumnWidth(1, 100 ) # 将第0列的单元格,设置成50宽度 self.qtablewidget.verticalHeader().setVisible(False) #隐藏水平表头 #self.qtablewidget.setDisabled(True) #设置不可编辑 self.setLayout(vlayout) self.current_index = 0 def tableupdate(self,dir, pic_num, pushbtn ) -> None: self.qtablewidget.setRowCount(self.current_index+1) #设置行 diritem = QTableWidgetItem(str(dir)) self.qtablewidget.setItem( self.current_index, 0, diritem) pic_numitem = QTableWidgetItem(str(pic_num)) self.qtablewidget.setItem( self.current_index, 1, pic_numitem) self.qtablewidget.setCellWidget( self.current_index, 2, pushbtn ) self.current_index += 1
class CreatePatientDialog(QDialog): def __init__(self, classification, patient, infoLabel, parent=None): super(CreatePatientDialog, self).__init__(parent) self.setWindowTitle('Create new patient') layout = QVBoxLayout() self.setLayout(layout) self.setMinimumWidth(200) self.patient = patient self.classifyExercises = classification self.infoLabel = infoLabel self.subjectEdit = QLineEdit() self.subjectEdit.setFixedHeight(30) self.subjectEdit.setText('Jozsika') self.subjectEdit.setStyleSheet(CustomQStyles.lineEditStyle) self.ageEdit = QLineEdit() self.ageEdit.setFixedHeight(30) self.ageEdit.setValidator(QIntValidator()) self.ageEdit.setText('5') self.ageEdit.setStyleSheet(CustomQStyles.lineEditStyle) self.subjectButton = QPushButton('Add patient') self.subjectButton.setFixedHeight(30) self.subjectButton.setStyleSheet(CustomQStyles.outlineButtonStyle) self.subjectButton.clicked.connect(self.onSubjectSelected) self.subjectButton.setContentsMargins(5, 15, 5, 5) formContainer = QWidget() self.formLayout = QFormLayout() self.formLayout.addRow('Name', self.subjectEdit) self.formLayout.addRow('Age', self.ageEdit) self.formLayout.addWidget(self.subjectButton) self.formLayout.setFormAlignment(Qt.Alignment.AlignCenter) formContainer.setLayout(self.formLayout) formContainer.setStyleSheet( "background-color: white; border-radius: 7px;") layout.addWidget(formContainer) def onSubjectSelected(self): if self.classifyExercises is not None \ and "" != self.subjectEdit.text() \ and "" != self.ageEdit.text(): self.subject = self.subjectEdit.text() self.classifyExercises.subject = self.subject self.classifyExercises.age = self.ageEdit.text() self.infoLabel.setText("Subject name set to " + self.subject + ", age " + self.classifyExercises.age) self.close()