Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSvgWidget blocking interaction with other widgets.



  • This is the SVG:

    <svg id="svgLED" width="640" height="480" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <linearGradient id="svg_6" x1="0" y1="0" x2="1" y2="0">
          <stop stop-color="#bfbfbf" offset="0"/>
          <stop stop-color="#404040" offset="1"/>
        </linearGradient>
        <linearGradient id="svg_11" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad">
          <stop stop-color="#dd0000" stop-opacity="0.992188" offset="0"/>
          <stop stop-color="#820101" stop-opacity="0.988281" offset="1"/>
        </linearGradient>
        <linearGradient id="svg_14" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad">
          <stop stop-color="#ffffff" stop-opacity="0.996094" offset="0"/>
          <stop stop-color="#d30606" stop-opacity="0.984375" offset="0.703125"/>
        </linearGradient>
      </defs>
      <g transform="translate(10,10) scale(.1)">
        <circle id="svgLED@[id]_c1" fill="url(#svg_6)" 
          	    stroke-width="17.5" stroke-linecap="round" 
    	    cx="320" cy="240" r="196.125" id="svg_3" 
    	    fill-opacity="0.77" transform="rotate(90, 320, 240)"/>
        <circle id="svgLED@[id]_c2" fill="url(#svg_6)" 
                stroke-width="17.5" stroke-linecap="round" 
                fill-opacity="0.64" cx="319.252837" cy="239.999045" 
                r="160" id="svg_7"/>
        <circle id="svgLED@[id]_c3" fill="url(#svg_11)" stroke-width="17.5" 
                stroke-linecap="round" cx="320.000535" cy="240.001698" r="150"/>
        <ellipse id="svgLED@[id]_e1" fill="url(#svg_14)" stroke-width="17.5" 
                stroke-linecap="round" cx="250.179609" cy="170.124194" 
                rx="75.675959" ry="44.402987" id="svg_20" 
                transform="rotate(-47.7626, 250.18, 170.125)"/>
      </g>
    </svg>
    

    This is the C++ that renders the widget:

    if ( pobjNode->strGetNodeName().compare(clsXMLnode::mscszNodeSVGroot) == 0 ) {
      QString strID = pobjNode->strGetAttribute(clsXMLnode::mscszAttrID);
    
      if ( strID.isEmpty() != true ) {
        clsXMLnode* pobjParent = pobjNode->pobjGetGUIParent();
    
        if ( pobjParent != nullptr ) {
          QWidget* pobjParWidget = pobjParent->pobjGetWidget();
    
          if ( pobjParWidget != nullptr ) {
            QByteArray bytArrSVG = pobjNode->bytArrDocument();
            QSvgWidget* pobjSVGwidget = new QSvgWidget(pobjParWidget);
            pobjSVGwidget->load(bytArrSVG);
            pobjSVGwidget->show();
          }
        }
      }
    }
    

    The SVG is intentionally rendered very small, so it appears as a very small image at the top left of the window. The problem is that with this widget present everything else in the window is blocked, what I mean is that there are buttons under the SVG and also text edit widgets, none of these will accept clicks whilst the SVG is visible. The only widget that does continue to work is a slider on the right of the window.
    Screenshot 2020-08-27 at 08.51.00.png
    The screenshot shows a demo, the red LED is the SVG, no other widgets in the window work except the slider, yet if I remove the SVG everything works.

    What is wrong?


  • Lifetime Qt Champion

    @SPlatten How big is pobjSVGwidget? Maybe it covers all these other widgets? What is pobjParWidget?



  • @jsulm The SVG widget is shown in the screen shot I added, its very small.

    pobjParent is a pointer to the Window node, pobjParWidget is the widget associated with the window node.


  • Lifetime Qt Champion

    @SPlatten said in QSvgWidget blocking interaction with other widgets.:

    its very small

    The icon is very small, but not necessarily the widget.



  • @jsulm , how can I tell? I am just parsing the parent to the SVG widget, I though the QSvgWidget would get its geometry from the SVG itself?

    I'm scaling the SVG in the transform, however having just added debug to display the geometry, this doesn't seem to effect the width and height of the SVG which is still 640x480.


  • Lifetime Qt Champion

    @SPlatten said in QSvgWidget blocking interaction with other widgets.:

    I though the QSvgWidget would get its geometry from the SVG itself?

    That I don't know. You could try to set fix size on SVG widget and see whether other widgets work then (just to see whether my guess is correct).



  • @jsulm I've just removed the width and height attributes from the SVG, now everything works perfectly.


  • Lifetime Qt Champion

    @SPlatten That answers your question: "I though the QSvgWidget would get its geometry from the SVG itself?" :-)



  • @SPlatten said in QSvgWidget blocking interaction with other widgets.:

    I though the QSvgWidget would get its geometry from the SVG itself?

    No, it would not. It will only update the size hint of the widget.
    You are supposed to adjust the size yourself.



  • @jsulm , yes, but shouldn't that take into account any scaling transformation?


  • Lifetime Qt Champion

    @SPlatten Scaling is something you usually have to explicitly do/trigger. QLabel will not do scaling by default, for example, if I remember correctly.



  • @jsulm qlabel->setScaledContents(bool) default is false;


Log in to reply