gpt4 book ai didi

python - 将Qcombobox的Qsettings写入文件而不关闭Widget

转载 作者:行者123 更新时间:2023-12-01 06:57:17 25 4
gpt4 key购买 nike

Qtablewidget 作为启动小部件运行,并将 Con 小部件导入到 QTableWidget。来自QCombobox 希望保存并恢复到具有目录路径的文件。每个小部件和布局都可以工作,问题在于 QCombobox 保存功能。认为启动并运行应用程序,当 Qcombobox 的值更改时, self.writeSettings 函数应该运行并写入?但它不起作用。想知道这里出了什么问题吗?任何帮助表示赞赏。我在下面复制了最少且高效的代码。

class CON(QtWidgets.QWidget):
def __init__(self, rowTable, parent=None):
super(CON, self).__init__(parent)
self.rowtable = rowTable
self.combo = QtWidgets.QComboBox()
self.combo.addItems(["15","20","25","30","37","45","50","55",
"60","67","75","85","95","105"])

------------------------------------

self.combo.activated.connect(self.setdata)
self.readSettings()

@QtCore.pyqtSlot(int)
def setdata(self, index):
self.writeSettings()


def readSettings(self):
settings = QtCore.QSettings('files/con{}.ini'.format(self.rowtable) ,QtCore.QSettings.IniFormat)
settings.beginGroup("Con")
self.combo.setCurrentIndex(settings.value("Conoption", 4))
settings.endGroup()

def writeSettings(self):
settings = QtCore.QSettings('files/con{}.ini'.format(self.rowtable) ,QtCore.QSettings.IniFormat)
settings.beginGroup("Con")
settings.setValue("Conoption",self.combo.currentIndex())
settings.endGroup()

最佳答案

我得到的唯一错误是读取的值被解释为 str,因此为了避免这种情况,您必须指示读取的类型:

settings.beginGroup("Con")
self.combo.setCurrentIndex(settings.value("Conoption", 4, <b>int</b>))
settings.endGroup()

关于python - 将Qcombobox的Qsettings写入文件而不关闭Widget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58757374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com