马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 timmylulu2010 于 2020-6-23 14:20 编辑
求助请教一个折腾了很久的问题,一直找不到解决问题的办法。
问题:设计一个界面分为左右两部分,左边是一个tree,下拉多个item;右边是一个widget,widget里的控件随着点击左边tree上不同的item而不停切换(这里的切换我为了后期灵活扩展方便,并没有预先做好不同item对应的widget,而是在每次点击item的时候,根据item的配置信息临时生成右边widge里的内容,每次生成新的内容前会把右边widget先做一次清空处理)。逻辑上来看没什么问题,但是实际使用的时候遇到一个麻烦,如果鼠标点击切换不同item时候手速很快,就会产生右边界面重影现象,貌似就是上一次的widget没有清空完毕,新的widget就生成了的感觉。所以为了解决这个问题,试了多种方案,例如创建一个全局变量,通过true false来限制界面生成函数的执行;还试过用锁去将函数入口锁住,等函数执行完再释放。但这些方案都不起作用。贴上两段代码:
下面是点击tree下的item时,回调函数里的内容,其中self.resultUpdateShow(itemname)是用来实现右边widget擦除后重建的函数。 def onClicked(self,qmodeLindex):
self.tree.blockSignals(True)
item=self.tree.currentItem()
if self.notice['selectAll'][self.language] == item.text(0):
print('不做任何操作')
self.tree.setCurrentItem(self.lastItem)
else:
#onClickSemaphore.acquire()
print('click状态为')
print(self.onClickStatus)
if self.onClickStatus:
time.sleep(0.1)
self.lastItem = item
print('点击调用')
itemname = item.text(0)
self.resultUpdateShow(itemname)
##onClickSemaphore.release()
currentModeName = self.project['itemList'][self.project['defaultChipId']][self.project['defaultMode'][self.project['defaultChipId']]]['name']
currentItemList = self.project['itemList'][self.project['defaultChipId']][self.project['defaultMode'][self.project['defaultChipId']]]['item']
print('点击项目名称后,当前的项目列表的长度为')
print(len(self.itemList))
print('当前项目名称为')
print(self.project['name'])
if currentModeName == 'VR' or currentModeName == 'SP':
if self.itemList[len(self.itemList) - 1].checkState(0) == 2:
micLPESQID = self.itemNameTab.index('micLoutQualityL')
micRPESQID = self.itemNameTab.index('micLoutQualityR')
micLLevelID = self.itemNameTab.index('micLoutLevelL')
micRLevelID = self.itemNameTab.index('micLoutLevelR')
noiseLID = self.itemNameTab.index('noiseFloorL')
noiseRID = self.itemNameTab.index('noiseFloorR')
self.itemList[micLPESQID].setCheckState(0,Qt.Checked)
self.itemList[micRPESQID].setCheckState(0,Qt.Checked)
self.itemList[micLLevelID].setCheckState(0,Qt.Checked)
self.itemList[micRLevelID].setCheckState(0,Qt.Checked)
self.itemList[noiseLID].setCheckState(0,Qt.Checked)
self.itemList[noiseRID].setCheckState(0,Qt.Checked)
for i in range(len(self.itemList)):
currentItemList[i]['select'] = self.itemList[i].checkState(0)
print('Key=%s'%(item.text(0)))
saveProjectParam(self.project)
else:
print('-----------------不动不动-------------------')
self.tree.setCurrentItem(self.lastItem)
self.tree.blockSignals(False)
下面是self.resultUpdateShow(itemname)函数实体内容。 def resultUpdateShow(self, itemname):
print('\n所申请')
resultUpdateSemaphore.acquire()
self.gl = globalGet()
self.language = self.gl['language']
self.projectList = self.gl['project']
Flag, self.project = getProjectParam(self.projectList['list'][self.projectList['default']])
self.resultTab = {}
self.checkTab = {}
print('清除右边窗口')
#for childWidget in self.right_widget.children():
# self.right_widget.removeItem(childWidget)
# childWidget.close()
# childWidget.destroy(True, True)
for i in range(self.right_layout.count()):
tempwidget = self.right_layout.itemAt(0).widget()
#self.right_layout.itemAt(0).widget().close()
self.right_layout.removeWidget(tempwidget)
tempwidget.close()
tempwidget.destroy(True, True)
#self.main_layout.removeWidget(self.right_widget)
#resultUpdateSemaphore.release()
currentItemList = self.project['itemList'][self.project['defaultChipId']][self.project['defaultMode'][self.project['defaultChipId']]]['item']
self.currentItemID = self.itemTab.index(itemname)
resultLabel = QLabel(itemname)
self.right_layout.addWidget(resultLabel)
currentItemName = currentItemList[self.currentItemID]['name']
currentItemThreshold = currentItemList[self.currentItemID]['threshold']
print(currentItemName)
print('新建右边窗口')
#resultUpdateSemaphore.acquire()
if const['itemList'][currentItemName]['type'] == 'value':
if 'resultTab' in currentItemList[self.currentItemID]:
self.resultTab = currentItemList[self.currentItemID]['resultTab']
if 'checkTab' in currentItemList[self.currentItemID]:
self.checkTab = currentItemList[self.currentItemID]['checkTab']
self.TableWidget = QTableWidget()
self.TableWidget.setStyleSheet("background-color: rgb(255,255, 255)")
resultTableVHeader = []
self.TableWidget.setRowCount(len(const['itemList'][currentItemName]['resultSection']))
for resultSection in const['itemList'][currentItemName]['resultSection']:
resultTableVHeader.append(resultSection['display'][self.language])
if currentItemThreshold:
self.TableWidget.setColumnCount(5)
else:
self.TableWidget.setColumnCount(2)
self.TableWidget.setHorizontalHeaderLabels(self.notice['resultTableHHeader'][self.language])
self.TableWidget.setVerticalHeaderLabels(resultTableVHeader)
self.TableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.TableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.TableWidget.clearContents()
self.valueInit(self.TableWidget)
self.right_layout.addWidget(self.TableWidget)
elif const['itemList'][currentItemName]['type'] == 'curve':
if 'resultTab' in currentItemList[self.currentItemID]:
self.resultTab = currentItemList[self.currentItemID]['resultTab']
if 'checkTab' in currentItemList[self.currentItemID]:
self.checkTab = currentItemList[self.currentItemID]['checkTab']
logButton = QPushButton()
logButton.setText(self.notice['logaxis'][self.language])
LinearButton = QPushButton()
LinearButton.setText(self.notice['linearaxis'][self.language])
self.checkLabel = QLabel()
#self.checkLabel.setText('xxx')
#self.checkLabel.setStyleSheet("font:24pt '楷体';color: rgb(255, 0, 0)")
self.fig = plt.Figure()
self.canvas = FC(self.fig)
self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.canvas.updateGeometry()
if const['itemList'][currentItemName]['method'] == 'FR':
ylabel = 'dBFS'
elif const['itemList'][currentItemName]['method'] == 'THD':
ylabel = '%'
elif const['itemList'][currentItemName]['method'] == 'SPL':
ylabel = 'dBSPL'
self.curveInit(self.fig, self.canvas, ylabel)
LinearButton.clicked.connect(self.slot_btn_start)
logButton.clicked.connect(self.slot_btn_start1)
buttonWidget = QWidget()
buttonLayout = QHBoxLayout()
buttonWidget.setLayout(buttonLayout)
buttonLayout.addWidget(logButton)
buttonLayout.addWidget(LinearButton)
labelWidget = QWidget()
labelWidget.setStyleSheet("background-color: rgb(255, 255, 255)")
labelLayout = QHBoxLayout()
labelWidget.setLayout(labelLayout)
labelLayout.addStretch(1)
labelLayout.addWidget(self.checkLabel)
labelLayout.addStretch(1)
self.right_layout.addWidget(self.canvas)
self.right_layout.addWidget(labelWidget)
self.right_layout.addWidget(buttonWidget)
self.right_layout.setSpacing(0)
elif const['itemList'][currentItemName]['type'] == 'waveform':
if 'resultTab' in currentItemList[self.currentItemID]:
self.resultTab = currentItemList[self.currentItemID]['resultTab']
if 'checkTab' in currentItemList[self.currentItemID]:
self.checkTab = currentItemList[self.currentItemID]['checkTab']
self.TableWidget = QTableWidget()
self.TableWidget.setMaximumHeight(150)
self.TableWidget.setStyleSheet("background-color: rgb(255,255, 255)")
resultTableVHeader = []
tablerowCount = 0
for resultSection in const['itemList'][currentItemName]['resultSection']:
if resultSection['type'] == 'sample' or resultSection['type'] == 'value':
tablerowCount = tablerowCount +1
resultTableVHeader.append(resultSection['display'][self.language])
self.TableWidget.setRowCount(tablerowCount)
if currentItemThreshold:
self.TableWidget.setColumnCount(5)
else:
self.TableWidget.setColumnCount(2)
self.TableWidget.setHorizontalHeaderLabels(self.notice['resultTableHHeader'][self.language])
self.TableWidget.setVerticalHeaderLabels(resultTableVHeader)
self.TableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.TableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.TableWidget.clearContents()
self.valueInit(self.TableWidget)
self.right_layout.addWidget(self.TableWidget)
buttonWidget = QWidget()
buttonWidget.setStyleSheet("background-color: rgb(255, 255, 255)")
buttonLayout = QHBoxLayout()
buttonWidget.setLayout(buttonLayout)
for resultSection in const['itemList'][currentItemName]['resultSection']:
if resultSection['type'] == 'curve':
waveformButton = PPathButton(self, resultSection['display'][self.language])
waveformButton.click.connect(self.wave_btn_start)
buttonLayout.addWidget(waveformButton)
plt.ylim(-40000, 40000)
plt.xlim(0,30)
self.fig = plt.Figure()
self.canvas = FC(self.fig)
self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.canvas.updateGeometry()
for resultSection in const['itemList'][currentItemName]['resultSection']:
if resultSection['type'] == 'curve':
self.waveformInit(self.fig, self.canvas, resultSection)
break
self.right_layout.addWidget(self.canvas)
self.right_layout.addWidget(buttonWidget)
self.main_layout.addWidget(self.right_widget)
#time.sleep(1)
resultUpdateSemaphore.release()
print('锁释放\n')
|