[PyQt] including Unicode in QListWidget

David Beck dbeck at ualberta.ca
Sun Jun 17 17:29:58 BST 2012


I am trying to build a GUI for navigating through a large XML database on a Mac running OS 10.7, Python 3.3, PyQt 4. I want to get a list of the text in all of the nodes called <Orth> and put them into a QListWidget called "hLexNav". To do this, I wrote the following bit of code (this isn't the whole thing, just the parts that are supposed to add items to the listbox):


import sys
from PyQt4 import QtCore, QtGui
from xml.dom import minidom
import xml.etree.ElementTree as etree
from fieldbookGui import Ui_Fieldbook
import images
import btnCmds
 
class MyForm(QtGui.QMainWindow):
  def __init__(self, parent=None):
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_Fieldbook()
    self.ui.setupUi(self)


    xmltree = etree.parse('BabyDb.xml')
    root = xmltree.getroot()
    for child in root:
      self.ui.hLexNav.addItem(child.findtext('Orth'))

The first 25 items that are returned by child.findtext('Orth') are:

['a:', 'a:cháj', 'a:chulá:', "a:hé:xtu'", 'a:ho:tán', 'a:kús', "a:li:ma'htín", 'a:li:stá:n', 'a:má', "a:ma'ha:'pi'tzí'n", 'a:mixtzayán', 'a:nanú:', 'a:tú:n', 'a:tzá:', "a:tzemá'j", 'a:xí:lh', 'a:xtúm', 'a:xú:x', "a:'hála'", "a:'j", "a:'jmá", "a:'jnanú:", "a:'jtzá:", "a:'jtzananú:", "a:'kní:"]

In the QListWidget created by this code, I see only items corresponding to those elements that do not contain accented vowels (here, those that don't contain "á", "ú", etc.); items that correpsond to strings with accented vowels are left empty. Further experimentation with addItem( ), addItems(), and insertItem( ) show that any string that contains an non-ASCII character results in an empty Item being inserted into the QListWidget.

Any ideas about what is going on would be appreciated.


More information about the PyQt mailing list