我尝试使用PyQt编写python脚本。我想从sqlite db中获取一些信息,然后在滚动区域内的复选框中显示它,以防列表变得太大:
def addCheckBox(self):
cbCurrentTxt = str(self.comboBox.currentText())
db = sqlite3.connect("data.db")
x = 10
for checkBoxPop in db.execute("SELECT * FROM users WHERE week='"+cbCurrentTxt+"';"):
print checkBoxPop
self.checkBox = QtGui.QCheckBox(self.scrollArea)
self.checkBox.setGeometry(QtCore.QRect(10, x, 95, 25))
self.checkBox.setText(_translate("MainwiNdow", str(checkBoxPop[1]), None))
self.checkBox_2 = QtGui.QCheckBox(self.scrollArea)
self.checkBox_2.setGeometry(QtCore.QRect(120, x, 95, 25))
self.checkBox_2.setText(_translate("MainwiNdow", str(checkBoxPop[3]), None))
for i in checkBoxPop[1]:
print "coord" + str(x)
x += 4
我使用组合框来获得一周:
def populateWeekCB(self):
db = sqlite3.connect("data.db")
cursor = db.cursor()
self.comboBox.clear()
for cbItemsDB in db.execute("select * from week"):
print cbItemsDB
self.comboBox.addItem(cbItemsDB[0])
self.comboBox.activated[str].connect(self.addCheckBox)
选择一周后,我想显示复选框,但它们没有显示。