Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QSvgWidget animated SVG not working for animate (but ok for animateTransform)
Forum Updated to NodeBB v4.3 + New Features

QSvgWidget animated SVG not working for animate (but ok for animateTransform)

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 2.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    supafly251
    wrote on last edited by supafly251
    #1

    Hi,

    I am trying to display an animated SVG using QSvgWidget. Works with svg's animateTranform, but does not work with simple animate. The code is as follows:

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtSvg import QSvgWidget, QSvgRenderer
    
    # if there is only ANIMATE below (without ANIMATETRANSFORM), animated() returns false and no animation is shown.
    # with both, animated() returns true and only animateTransform plays.
    
    svg_str = """
    <svg width="120"
         height="120"
         viewBox="0 0 120 120"
         version="1.1"
         xmlns="http://www.w3.org/2000/svg">
      
      <rect x="10" y="10" width="100" height="100">
        <animateTransform
            attributeName="transform"
            begin="0s"
            dur="20s"
            type="rotate"
            from="0 60 60"
            to="360 60 60"
            repeatCount="indefinite"
            />
        <animate 
            attributeName="x"
            from="-100"
            to="120"
            dur="10s"
            repeatCount="indefinite"
            begin="0s" />
      </rect>
    </svg>
    """
    
    svg_bytes = bytearray(svg_str, encoding='utf-8')
    
    app = QApplication(sys.argv)
    
    svgWidget = QSvgWidget()
    svgWidget.renderer().load(svg_bytes)
    svgWidget.setGeometry(100,100,300,300)
    svgWidget.show()
    
    print(svgWidget.renderer().isValid())
    print(svgWidget.renderer().animated())
    
    sys.exit(app.exec_())
    

    Also tried to put the svg code in a separate svg file, as well as placing the svg widget in a QMainWindow with a layout, but it does not change anything.

    Am I missing something? Is only animateTransform supported by svg widget?

    1 Reply Last reply
    0
    • DenniD Offline
      DenniD Offline
      Denni
      wrote on last edited by Denni
      #2

      @supafly251 cannot say exactly but a quick search did find this from back in 2014 so its a sort of issue (functionality) that exists but has not been fully explained (that I could fine):
      https://stackoverflow.com/questions/23095732/why-do-animated-elements-in-qtsvg-need-to-be-of-type-animatetransform-in-order-t

      Also it would help greatly if you denoted what version of python and what version-&-flavor of qt that you are using

      Note I said issue (functionality) because it might not be an issue but simply how its supposed to work -- but without any specific documentation on it it is kind of hard to say. This to say looking up the QSvgRenderer there is no reference to animateTransform nor could I find any documentation for animateTransform associated with pyqt5

      Addendum: It appears (to me at least) that animateTransform is not part of pyqt at all but part of the SVG object underlying it -- you will have to dig into python's documentation on the SVG object to better understand this functionality.

      madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

      1 Reply Last reply
      0
      • S Offline
        S Offline
        supafly251
        wrote on last edited by supafly251
        #3

        Hello, thank you for your answer. I am using latest version of Qt (5.12 I think) with PyQt 5 and Python 3.7.3. I found that answer on SO after posting my own, and seems nobody really knows. Anyway it works, but also not with the same performance as in a browser (svg widget animation runs slower than in codepen, same machine and same code). Guess this is not the best way to programatically animate in Qt/Python. Thanks!

        1 Reply Last reply
        0
        • DenniD Offline
          DenniD Offline
          Denni
          wrote on last edited by
          #4

          Okay so does this mean your initial question here has been resolved (at least as far as it can be) if yes then maybe you should mark this thread resolved (yes/no?) and your welcome

          madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xerius65
            wrote on last edited by xerius65
            #5

            No! animate_transform implementes only a small subset of animate! At the moment this part of the SVG standard seems not implemented.

            It seems the animate keyword is completely ignored as print(svgWidget.renderer().animated()) returns false when only the animate keyword is present.

            1 Reply Last reply
            0
            • DenniD Offline
              DenniD Offline
              Denni
              wrote on last edited by Denni
              #6

              Okay well the SVG issue to me appears to be a python related issue and not a pyqt issue since it is the python that serves up the SVG API unless I misunderstood something when I glanced over that (aka I could be wrong it wont be the first time and most likely not the last if I am)

              madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved