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. How to display SVG in a QGroupBox ?

How to display SVG in a QGroupBox ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 676 Views
  • 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.
  • H Offline
    H Offline
    Hirisar
    wrote on last edited by Hirisar
    #1

    Hi everyone !

    I'm trying to display some SVG files in my software. In some places, the SVG is displayed. In some others, not...

    The code to load the files is the same for the entire set of images and if I force to display the same SVG everywhere, the problem remains the same.

    SvgWebViewWidget::SvgWebViewWidget ( const QString pImagePath, QWidget* pParent )
         : QWebEngineView( pParent )
     {
             // Load image
             this->load( QUrl::fromLocalFile( pImagePath ) );
         }
     }
    
    QGroupBox* lChildContainer = new QGroupBox( Name );
    lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
    lChildContainer->setLayout( new QVBoxLayout() );
    lChildContainer->layout()->setSpacing( 0 );
    
     //pContainer is a QWidget *
     pContainer->layout()->addWidget( lChildContainer );
    
     QWidget* svgimage = new SvgWebViewWidget( lImagePath, this );
    
    lChildContainer->layout()->addWidget( svgimage);
    

    If I add the Image directly to pContainer, the SVG is displayed (but I need the QGroupBox).

    Do you have any idea to solve this bug ? Thanks

    jsulmJ 1 Reply Last reply
    0
    • H Offline
      H Offline
      Hirisar
      wrote on last edited by
      #10

      Hi !

      I really want to thank everyone who helped me ! I found the bug somewhere deeply in the code (actually, I was doing something else than finding it).
      I have a filter which hides or shows what I want. And when I upgraded WebView to WebEngineView, I forget to change it in the filter.

      Thanks again.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #2

        Hi, there is a QSvgWidget class in the Qt SVG module

        H 1 Reply Last reply
        2
        • H Hirisar

          Hi everyone !

          I'm trying to display some SVG files in my software. In some places, the SVG is displayed. In some others, not...

          The code to load the files is the same for the entire set of images and if I force to display the same SVG everywhere, the problem remains the same.

          SvgWebViewWidget::SvgWebViewWidget ( const QString pImagePath, QWidget* pParent )
               : QWebEngineView( pParent )
           {
                   // Load image
                   this->load( QUrl::fromLocalFile( pImagePath ) );
               }
           }
          
          QGroupBox* lChildContainer = new QGroupBox( Name );
          lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
          lChildContainer->setLayout( new QVBoxLayout() );
          lChildContainer->layout()->setSpacing( 0 );
          
           //pContainer is a QWidget *
           pContainer->layout()->addWidget( lChildContainer );
          
           QWidget* svgimage = new SvgWebViewWidget( lImagePath, this );
          
          lChildContainer->layout()->addWidget( svgimage);
          

          If I add the Image directly to pContainer, the SVG is displayed (but I need the QGroupBox).

          Do you have any idea to solve this bug ? Thanks

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #3

          @Hirisar

          QGroupBox* lChildContainer = new QGroupBox( Name );
          lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
          lChildContainer->setLayout( new QVBoxLayout() );
          lChildContainer->layout()->setSpacing( 0 );
          
          QWidget* svgimage = new SvgWebViewWidget( lImagePath, this );
          lChildContainer->layout()->addWidget(svgimage);
          
          lChildContainer->show();
          

          As shown in https://doc.qt.io/Qt-5/qgroupbox.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          H 1 Reply Last reply
          0
          • B Bonnie

            Hi, there is a QSvgWidget class in the Qt SVG module

            H Offline
            H Offline
            Hirisar
            wrote on last edited by
            #4

            @Bonnie said in How to display SVG in a QGroupBox ?:

            Hi, there is a QSvgWidget class in the Qt SVG module

            It does not fix the problem :'(

            B 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Hirisar

              QGroupBox* lChildContainer = new QGroupBox( Name );
              lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
              lChildContainer->setLayout( new QVBoxLayout() );
              lChildContainer->layout()->setSpacing( 0 );
              
              QWidget* svgimage = new SvgWebViewWidget( lImagePath, this );
              lChildContainer->layout()->addWidget(svgimage);
              
              lChildContainer->show();
              

              As shown in https://doc.qt.io/Qt-5/qgroupbox.html

              H Offline
              H Offline
              Hirisar
              wrote on last edited by
              #5

              @jsulm said in How to display SVG in a QGroupBox ?:

              @Hirisar

              QGroupBox* lChildContainer = new QGroupBox( Name );
              lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
              lChildContainer->setLayout( new QVBoxLayout() );
              lChildContainer->layout()->setSpacing( 0 );
              
              QWidget* svgimage = new SvgWebViewWidget( lImagePath, this );
              lChildContainer->layout()->addWidget(svgimage);
              
              lChildContainer->show();
              

              As shown in https://doc.qt.io/Qt-5/qgroupbox.html

              Thanks for this solution but the problem stays the same. If I load a PNG file instead of a SVG file, it runs properly (but I need to use SVG).
              And if I load a SVG file and I add a QDoubleSpinBox to lChildContainer, it works (but I don't want the last one)...

              Weird :'(

              1 Reply Last reply
              0
              • H Hirisar

                @Bonnie said in How to display SVG in a QGroupBox ?:

                Hi, there is a QSvgWidget class in the Qt SVG module

                It does not fix the problem :'(

                B Offline
                B Offline
                Bonnie
                wrote on last edited by
                #6

                @Hirisar Just think maybe there is no need to use a QWebEngineView to show SVG.
                That's too heavy ;)

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  SimonSchroeder
                  wrote on last edited by
                  #7

                  Could it be that because of the layout your SVG widget is shrunk down to 0 size while with a PNG it is not? Try calling setMinimumSize on the SVG widget to figure out if this is the problem.

                  H 1 Reply Last reply
                  0
                  • S SimonSchroeder

                    Could it be that because of the layout your SVG widget is shrunk down to 0 size while with a PNG it is not? Try calling setMinimumSize on the SVG widget to figure out if this is the problem.

                    H Offline
                    H Offline
                    Hirisar
                    wrote on last edited by
                    #8

                    @SimonSchroeder I tried but it didn't solve my problem...

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Hi
                      I have zero issues showing a SVG in Groupbox using QSvgWidget.

                         QGroupBox* lChildContainer = new QGroupBox( "Name", centralWidget() );
                          lChildContainer->setStyleSheet( "QGroupBox { font-weight: bold };" );
                          lChildContainer->setLayout( new QVBoxLayout() );
                          lChildContainer->layout()->setSpacing( 0 );
                      
                          QSvgWidget* svgimage = new QSvgWidget( ":/Panneau_attention.svg" );
                          lChildContainer->layout()->addWidget(svgimage);
                      
                          lChildContainer->show();
                      
                      

                      so either its related to SvgWebViewWidget or the actual code itself.

                      alt text

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        Hirisar
                        wrote on last edited by
                        #10

                        Hi !

                        I really want to thank everyone who helped me ! I found the bug somewhere deeply in the code (actually, I was doing something else than finding it).
                        I have a filter which hides or shows what I want. And when I upgraded WebView to WebEngineView, I forget to change it in the filter.

                        Thanks again.

                        1 Reply Last reply
                        2

                        • Login

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