[PySide] QTextBrowser.setSource()

Tim Doty thoromyr at mac.com
Tue Jun 18 03:58:06 CEST 2013


I'm having a problem with QTextBrowser.setSource() -- the error is:

QTextBrowser: No document for /Users/tim/Documents/Development/lithophane/HCLithophaneCreator.html

But… there actually is such a file and it is readable by the current user. No, there isn't a typo in the path: copying and pasting that path works with, e.g., less. What *really* puzzles me is that identical code (copy and paste) from a different project works.

The code that creates the dialog holding the text browser is:

 class HelpContentsDlg(QDialog):
    """
        Displays a help dialog providing information about the application.
    """
    def __init__(self, page, parent=None):
        super(HelpContentsDlg, self).__init__(parent)
        browser = QTextBrowser()
        browser.setSearchPaths([":/"])
        browser.setSource(QUrl(page))
        browser.setOpenExternalLinks(True)
        layout = QVBoxLayout()
        layout.addWidget( browser )
        self.setLayout(layout)

This code is invoked by:

     def helpContents(self):
        if not self.helpContentsDlg:
            helpFile = os.path.join(os.path.dirname( os.path.realpath( __file__ ) ), __thisHelpFileName__)
            self.helpContentsDlg = HelpContentsDlg( helpFile, self)
            self.helpContentsDlg.setWindowTitle(__thisAppName__ + ' Help')
        self.helpContentsDlg.show()

the variable is defined toward the top of the application (in a block of similarly named variables)

__thisHelpFileName__ = "HCLithophaneCreator.html"

As already mentioned, this *identical* code (the only difference is the value for the help file name) works in a different application. Searching the Internet has not shed any light on the subject so I'm hoping someone here has an idea of what I'm doing wrong.

Ah, I'm running with Python 2.7.2, Qt 4.8.0 and PySide 1.1.1 on OS X.

Tim Doty


More information about the PySide mailing list