Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Animating SVG widget
Forum Updated to NodeBB v4.3 + New Features

Animating SVG widget

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 163 Views 1 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I have instances of QSvgWidget which create from a resource in my application:

    psvgRxIcon = new QSvgWidget(":/SVG_LED");
    psvgRxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    psvgRxIcon->setFixedSize(24, 24);
    

    I'm investigating the best way to animate and thanks to suggestions from @mrjj, I've added:

    pdocRxIcon = new QDomDocument();
    pfileRxIcon = new QFile(":/SVG_LED");
    pfileRxIcon->open(QIODevice::ReadOnly | QIODevice::Text);
    pdocRxIcon->setContent(pfileRxIcon);
    

    I've found the element I want to change, changed it and put it back in the attribute, the question is do I then have to re-create the widget every-time I change the document? Is there another way?

    There are no methods that return pointers or references in the document so its a bit of a pain to modify and put back. I have use setAttribute to put back the modified attribute back into the element.

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #2

      Done it, and it works, in the SVG resource I set the opacity to 0, then in this modification I change the opacity to 1:

          double dblOpacity = 1.0;
       
          QDomElement elRoot(mpdocRxIcon->firstChildElement());
          QDomNodeList lstNodes(elRoot.elementsByTagName(TraineeMonitor::mscszTagStop));
          bool blnAssign(false);
          for( int i=0; i<lstNodes.size(); i++ )
          {
              QDomNode ndStop(lstNodes.at(i));
              if ( !ndStop.isElement() )
              {
                  continue;
              }
              QDomElement elm(ndStop.toElement());
              QString strID(elm.attribute(TraineeMonitor::mscszAttrID));
              if ( strID.compare(TraineeMonitor::mscszLEDcolor) == 0 )
              {
                  QString strStyle(elm.attribute(TraineeMonitor::mscszAttrStyle));
                  QStringList slstStyles(strStyle.split(TraineeMonitor::mscszStyleDelimiter));
                  uint uintIdx = 0;
                  foreach( QString strStyle, slstStyles )
                  {
                      QStringList slstStyle(strStyle.split(TraineeMonitor::mscszAttrDelimiter));
                      strStyle = slstStyle[0];
                      if ( strStyle.compare(TraineeMonitor::mscszStyleStopOpacity) == 0 )
                      {
                          slstStyles[uintIdx] = strStyle +
                                                TraineeMonitor::mscszAttrDelimiter +
                                                QString::number(dblOpacity);
                          blnAssign = true;
                          break;
                      }
                      uintIdx++;
                  }
                  if ( blnAssign == true )
                  {
                      QString strNewStyle;
                      foreach( QString strStyle, slstStyles )
                      {
                          if ( strNewStyle.isEmpty() != true )
                          {
                              strNewStyle += TraineeMonitor::mscszStyleDelimiter;
                          }
                          strNewStyle += strStyle;
                      }
                      elm.setAttribute(TraineeMonitor::mscszAttrStyle, strNewStyle);
                      break;
                  }
              }
          }
          if ( blnAssign == true )
          {
              mpsvgRxIcon->load(mpdocRxIcon->toByteArray());
          }
      

      The final version will have a QTimer that increments the sets the opacity to 1 then decrements to 0 to fade out.

      Kind Regards,
      Sy

      1 Reply Last reply
      1

      • Login

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