Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1076081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:21:40+00:00 2026-05-16T21:21:40+00:00

How do I render glyphs in pyqt using the svggraphicsItem?

  • 0

How do I render glyphs in pyqt using the svggraphicsItem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:21:41+00:00Added an answer on May 16, 2026 at 9:21 pm

    Recently I found that svg files generated by Cairo do not plot properly in pyqt. The error comes from the use of glyphs which seem not to be shown in pyqt (this might be wrong but I couldn’t find any way of getting glyphs to render).

    I ended up writing a set of functions that will convert the glyphs to svg paths so the file will render normally.

    These could still use some improvements for rendering color and other style elements (which are locked in the functions that I wrote).

    These functions will need to be embedded in a class or have self removed to be used elsewhere.

    I just wanted people to have these so they wouldn’t have to search high and low like I did to find a way to render glyphs in pyqt.

    Hope for the best,
    Kyle

    def convertSVG(self, file): 
        dom = self._getsvgdom(file) 
        print dom 
        self._switchGlyphsForPaths(dom) 
        self._commitSVG(file, dom) 
    def _commitSVG(self, file, dom): 
        f = open(file, 'w') 
        dom.writexml(f) 
        f.close() 
    def _getsvgdom(self, file): 
        print 'getting DOM model' 
        import xml.dom 
        import xml.dom.minidom as mini 
        f = open(file, 'r') 
        svg = f.read() 
        f.close() 
        dom = mini.parseString(svg) 
        return dom 
    def _getGlyphPaths(self, dom): 
        symbols = dom.getElementsByTagName('symbol') 
        glyphPaths = {} 
        for s in symbols: 
            pathNode = [p for p in s.childNodes if 'tagName' in dir(p) and p.tagName == 'path'] 
            glyphPaths[s.getAttribute('id')] = pathNode[0].getAttribute('d') 
        return glyphPaths 
    def _switchGlyphsForPaths(self, dom): 
        glyphs = self._getGlyphPaths(dom) 
        use = self._getUseTags(dom) 
        for glyph in glyphs.keys(): 
            print glyph 
            nl = self.makeNewList(glyphs[glyph].split(' ')) 
            u = self._matchUseGlyphs(use, glyph) 
            for u2 in u: 
                print u2, 'brefore' 
                self._convertUseToPath(u2, nl) 
                print u2, 'after' 
    
    def _getUseTags(self, dom): 
        return dom.getElementsByTagName('use') 
    def _matchUseGlyphs(self, use, glyph): 
        matches = [] 
        for i in use: 
            print i.getAttribute('xlink:href') 
            if i.getAttribute('xlink:href') == '#'+glyph: 
                matches.append(i) 
        print matches 
        return matches 
    def _convertUseToPath(self, use, strokeD): 
        ## strokeD is a list of lists of strokes to make the glyph 
        newD = self.nltostring(self.resetStrokeD(strokeD, use.getAttribute('x'), use.getAttribute('y'))) 
        use.tagName = 'path' 
        use.removeAttribute('xlink:href') 
        use.removeAttribute('x') 
        use.removeAttribute('y') 
        use.setAttribute('style', 'fill: rgb(0%,0%,0%); stroke-width: 0.5; stroke-linecap: round; stroke-linejoin: round; stroke: rgb(0%,0%,0%); stroke-opacity: 1;stroke-miterlimit: 10; ') 
        use.setAttribute('d', newD) 
    def makeNewList(self, inList): 
        i = 0 
        nt = [] 
        while i < len(inList): 
            start = i + self.listFind(inList[i:], ['M', 'L', 'C', 'Z']) 
            end = start + self.listFind(inList[start+1:], ['M', 'L', 'C', 'Z', '', ' ']) 
            nt.append(inList[start:end+1]) 
            i = end + 1 
        return nt 
    def listFind(self, x, query): 
        for i in range(len(x)): 
            if x[i] in query: 
                return i 
        return len(x) 
    def resetStrokeD(self, strokeD, x, y): 
        nsd = [] 
        for i in strokeD: 
            nsd.append(self.resetXY(i, x, y)) 
        return nsd 
    def resetXY(self, nl, x, y): # convert a list of strokes to xy coords 
        nl2 = [] 
        for i in range(len(nl)): 
            if i == 0: 
                nl2.append(nl[i]) 
            elif i%2: # it's odd 
                nl2.append(float(nl[i]) + float(x)) 
            elif not i%2: # it's even 
                nl2.append(float(nl[i]) + float(y)) 
            else: 
                print i, nl[i], 'error' 
        return nl2 
    def nltostring(self, nl): # convert a colection of nl's to a string 
        col = [] 
        for l in nl: 
            templ = [] 
            for c in l: 
                templ.append(str(c)) 
            templ = ' '.join(templ) 
            col.append(templ) 
        return ' '.join(col)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to render partial view in some specific div without using ajax in asp.net
I want to render the partial view using ajax. When I submit the button,
How do you render a different .js.erb file while using Ajax? For example: <%
Goal: To render a google map using geolocation. I am trying to implement the
I am using RenderTargetBitmap.Render(panel) to take a snap of an items panel. However I
I've got a Python program using PIL to render text, and it works great
I just want to render QT widgets into a SFML window without using the
I am trying to render an activity feed kind of an UI using a
I render all my surfaces to a buffer, then at the end of the
If you begin to render points, render a ton of vertices, and then end,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.