PyQt database example
David MacQuigg
dmq at gain.com
Mon Mar 22 14:34:27 EST 2004
On Mon, 22 Mar 2004 08:30:18 +0100, "Leif B. Kristensen"
<junkmail at solumslekt.org> wrote:
>Can somebody point me to a quick example on how to display the result of
>an SQL query in a PyQt QListBox? I've googled in vain for this.
Assuming you can get the results of your SQL query into string form,
it should be just a matter of inserting those strings into your
widget.
I don't know if this will help you, but here is a snip from one of my
classes where I am processing a list of text lines and displaying
those lines in a QTextEdit widget. The fields in each line are padded
to make everything come out in nice columns.
The snag that hung me up when I first started using PyQt was not
realizing that the "QStrings" that come out of a Qt widget (a C++
thingy) have to be converted to Python strings ( with the str function
). It's OK going the other way, however. You can insert a Python
string ( p below ) into a PyQt widget.
def slotParse(self):
self.outputTextLabel.setText(self.simComboBox.currentText())
pystring = str(self.textEdit1.text()) # Convert QString to
pystring
modlist = pystring.splitlines()
plist = parseMods(modlist)
for p in plist:
self.textEdit2.insert(p + '\n')
-- Dave
More information about the Python-list
mailing list