我需要一种将sqlite.db中的某些行设置为pyqt textbrowser的方法,但是问题是它只放在最后一行。
cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))
for row in cur:
print('{0}'.format(row[0]))
self.SearchResults.setPlainText('{0}'.format(m))
我用过熊猫,但是
query = "SELECT text FROM Translation WHERE priority=2;"
df = pd.read_sql_query(query,conn)
self.SearchResults.setPlainText('{0}'.format(df['text']))
这不是我想要的。而且:
cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))
all_rows=cur.fetchall()
self.SearchResults.setPlainText('{0}'.format(all_rows))
答案 0 :(得分:1)
在第一个代码中,您每次迭代都将替换文本,解决方案是使用append()
cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))
self.SearchResults.clear() # clear previous text
for row in cur:
self.SearchResults.append('{0}'.format(str(row[0])))