[PyQt] including Unicode in QListWidget
Phil Thompson
phil at riverbankcomputing.com
Tue Jun 19 15:42:25 BST 2012
On Sun, 17 Jun 2012 10:29:58 -0600, David Beck <dbeck at ualberta.ca> wrote:
> 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.
It's a compiler bug, see...
http://bugs.python.org/issue13241
Tonight's snapshot will disable the PEP 393 support if LLVM is being used.
Another workaround is to enable Qt4's clang support...
cd /path/to/qt/mkspecs
ln -s unsupported/macx-clang macx-clang
Phil
More information about the PyQt
mailing list