def setValue(self, value):
""" select button according to the value """
qconfig.set(self.configItem, value) # 这里只能往全局 qconfig 里设置配置数据
for button in self.buttonGroup.buttons():
isChecked = button.property(self.configName) == value
button.setChecked(isChecked)
if isChecked:
self.choiceLabel.setText(button.text())
self.choiceLabel.adjustSize()
问题描述
由于工具设计时,需要一个全局配置,和一个基于项目的输出导出配置,也就是需要两套独立的配置文件和管理。
但在使用 common/components/settings/....Card 和 common/config 的过程中发现每一个控件的数据set都是使用 qconfig 来设置
也就是使用一个全局的 common/config 中的 qconfig实例进行保存,这导致无法使用多个 自定义config,因为无论
都会导致 qconfig 只能同时使用一套 _cfg 来进行数据的管理。
解决办法
抛砖引玉哈,说的不一定对。
当界面上引导用户对某一个自定义配置如 cfg2 进行操作时,将全局 qconfig 通过 load 方式加载进来 cfg2 。
可能需要对 config 和 各个 card 组件进行一定的重构,common/config.QConfig 拆分功能成 QConfig(负责管理) 和 QConfigSource(负责配置项定义可以是纯粹的数据型model)。仅做参考。