# 设置控件用setCellWidget
self.tableWidget_net.setCellWidget(i, 0, self.cfgLabForRow(self.set.cfg_net[i]["name"])) # 配置项 名称
def cfgLabForRow(self, name): # 生产一个lab
widget = QtWidgets.QWidget()
self.lab_temp = QtWidgets.QLabel(name)
self.lab_temp.setStyleSheet(''' text-align : center;
background-color : Snow;
height : 30px;
border-style: outset;
font : 20px ''')
hLayout = QtWidgets.QHBoxLayout()
hLayout.addWidget(self.lab_temp)
hLayout.setContentsMargins(2, 2, 2, 2)
widget.setLayout(hLayout)
return widget
def cfgComboBoxForRow(self, comList): # 生产一个下拉框
widget = QtWidgets.QWidget()
cb_temp = QtWidgets.QComboBox()
# self.lab_temp.addItem(comList)
cb_temp.addItems(comList)
cb_temp.setStyleSheet(''' text-align : center;
background-color : NavajoWhite;
height : 30px;
border-style: outset;
font : 20px ''')
# self.cb_temp.currentTextChanged.connect(self.data_change)
hLayout = QtWidgets.QHBoxLayout()
hLayout.addWidget(cb_temp)
hLayout.setContentsMargins(5, 2, 5, 2)
widget.setLayout(hLayout)
return widget
def cfgEditForRow(self, name):
widget = QtWidgets.QWidget()
self.lab_temp = QtWidgets.QLineEdit(name)
# self.lab_temp = QtWidgets.QTextEdit(name)
self.lab_temp.setStyleSheet(''' text-align : center;
background-color : NavajoWhite;
height : 30px;
border-style: outset;
font : 20px ''')
# self.lab_temp.setWordWrapMode(True)
self.lab_temp.editingFinished.connect(self.data_change)
hLayout = QtWidgets.QHBoxLayout()
hLayout.addWidget(self.lab_temp)
hLayout.setContentsMargins(5, 2, 5, 2)
widget.setLayout(hLayout)
return widget
# 读取控件用cellWidget
self.tableWidget_net.cellWidget(ii, 2).findChild(QtWidgets.QLineEdit).text()
self.tableWidget_net.cellWidget(ii, 2).findChild(QtWidgets.QComboBox).currentText()
# 修改控件属性
self.tableWidget_net.cellWidget(ii, 2).findChild(QtWidgets.QLineEdit).setText("111")