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 make a SVG at tab Widget ?
Forum Updated to NodeBB v4.3 + New Features

How to make a SVG at tab Widget ?

Scheduled Pinned Locked Moved Solved General and Desktop
55 Posts 6 Posters 10.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.
  • R RiceBall

    @jsulm said in How to make a SVG at tab Widget ?:

    @RiceBall said in How to make a SVG at tab Widget ?:

    How could I code it ??

    Using https://doc.qt.io/qt-5/qgraphicsscene.html#addItem ?

    Sorry, I have tried it.
    But I am not sure where is wrong.
    I can't show anything.(MY SVG is animtion)
    Can you help me check it ??

    QImage image1("C:/Users/shih.licheng/Documents/iHMI_2/splash1.svg");
        QGraphicsPixmapItem itm1(QPixmap::fromImage(image1));
        QGraphicsScene* scene = new QGraphicsScene;
        scene->addItem(&itm1);
        
        QImage image2("C:/Users/shih.licheng/Documents/iHMI_2/splash2.svg");
        QGraphicsPixmapItem itm2(QPixmap::fromImage(image2));
        scene->addItem(&itm2);
    
        QGraphicsView view(scene);
        view.show();
    

    And I have another easy question.
    if I use ui(graphics View).
    How could I replace above "QGraphicsView view(scene)"

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

    @RiceBall said in How to make a SVG at tab Widget ?:

    QGraphicsView view(scene);
    view.show();

    You're creating local QGraphicsView instance which is destroyed as soon as it goes out of scope (by the way you did not say where you actually have this code). Also check whether the paths are correct and what https://doc.qt.io/qt-5/qimage.html#isNull returns.

    "How could I replace above "QGraphicsView view(scene)"" - just use the view from ui->?

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

    R 1 Reply Last reply
    2
    • jsulmJ jsulm

      @RiceBall said in How to make a SVG at tab Widget ?:

      QGraphicsView view(scene);
      view.show();

      You're creating local QGraphicsView instance which is destroyed as soon as it goes out of scope (by the way you did not say where you actually have this code). Also check whether the paths are correct and what https://doc.qt.io/qt-5/qimage.html#isNull returns.

      "How could I replace above "QGraphicsView view(scene)"" - just use the view from ui->?

      R Offline
      R Offline
      RiceBall
      wrote on last edited by RiceBall
      #7

      @jsulm said in How to make a SVG at tab Widget ?:

      @RiceBall said in How to make a SVG at tab Widget ?:

      QGraphicsView view(scene);
      view.show();

      You're creating local QGraphicsView instance which is destroyed as soon as it goes out of scope (by the way you did not say where you actually have this code). Also check whether the paths are correct and what https://doc.qt.io/qt-5/qimage.html#isNull returns.

      "How could I replace above "QGraphicsView view(scene)"" - just use the view from ui->?

      1. I use it at Mainwindow.
        As you say, I can see it is shown suddenly then it is gone.
      2. I use graphic View UI at mainwindow.ui.
        How could I fix code about QGraphicsView view(scene)?

      attachment is my code.
      https://drive.google.com/open?id=17mOeeA11xWIo17LzSuDw6pcf9QvLePnH

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

        Hi
        I assume you want to use the one you put in the tab ?

        QGraphicsView view(scene);
        view.show();

        ui->graphicsView->setScene(scene);

        R 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          I assume you want to use the one you put in the tab ?

          QGraphicsView view(scene);
          view.show();

          ui->graphicsView->setScene(scene);

          R Offline
          R Offline
          RiceBall
          wrote on last edited by
          #9

          @mrjj said in How to make a SVG at tab Widget ?:

          Hi
          I assume you want to use the one you put in the tab ?

          QGraphicsView view(scene);
          view.show();

          ui->graphicsView->setScene(scene);

          Thank you for your reply.
          It looks like have loading something.

          But as you say , I think it just only show one moment.
          Where is wrong?

          0_1559611246187_73721276-3baa-43f8-84aa-5dd0616a88eb-image.png

          D 1 Reply Last reply
          0
          • R RiceBall

            @mrjj said in How to make a SVG at tab Widget ?:

            Hi
            I assume you want to use the one you put in the tab ?

            QGraphicsView view(scene);
            view.show();

            ui->graphicsView->setScene(scene);

            Thank you for your reply.
            It looks like have loading something.

            But as you say , I think it just only show one moment.
            Where is wrong?

            0_1559611246187_73721276-3baa-43f8-84aa-5dd0616a88eb-image.png

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #10

            @RiceBall

            like this:

            graphicsView->scene()->addWidget(new QSvgWidget(":/your.svg"));
            
            R 1 Reply Last reply
            1
            • D Devopia53

              @RiceBall

              like this:

              graphicsView->scene()->addWidget(new QSvgWidget(":/your.svg"));
              
              R Offline
              R Offline
              RiceBall
              wrote on last edited by
              #11

              @Devopia53 said in How to make a SVG at tab Widget ?:

              @RiceBall

              like this:

              graphicsView->scene()->addWidget(new QSvgWidget(":/your.svg"));
              

              Thank you for your reply.
              I try to fix it.
              But it show following message.
              0_1559618556774_7a0a23e1-f86a-4ff4-a3f2-68af5a9392c5-image.png

              D Pradeep P NP 2 Replies Last reply
              0
              • R RiceBall

                @Devopia53 said in How to make a SVG at tab Widget ?:

                @RiceBall

                like this:

                graphicsView->scene()->addWidget(new QSvgWidget(":/your.svg"));
                

                Thank you for your reply.
                I try to fix it.
                But it show following message.
                0_1559618556774_7a0a23e1-f86a-4ff4-a3f2-68af5a9392c5-image.png

                D Offline
                D Offline
                Devopia53
                wrote on last edited by
                #12

                @RiceBall

                first, in .pro

                QT += svg

                and then add

                #include <QSvgWidget>

                1 Reply Last reply
                2
                • R RiceBall

                  @Devopia53 said in How to make a SVG at tab Widget ?:

                  @RiceBall

                  like this:

                  graphicsView->scene()->addWidget(new QSvgWidget(":/your.svg"));
                  

                  Thank you for your reply.
                  I try to fix it.
                  But it show following message.
                  0_1559618556774_7a0a23e1-f86a-4ff4-a3f2-68af5a9392c5-image.png

                  Pradeep P NP Offline
                  Pradeep P NP Offline
                  Pradeep P N
                  wrote on last edited by Pradeep P N
                  #13

                  @RiceBall
                  Add QT += svg in .pro file

                  Refer Rendering SVG Files

                  Pradeep Nimbalkar.
                  Upvote the answer(s) that helped you to solve the issue...
                  Keep code clean.

                  R 1 Reply Last reply
                  4
                  • Pradeep P NP Pradeep P N

                    @RiceBall
                    Add QT += svg in .pro file

                    Refer Rendering SVG Files

                    R Offline
                    R Offline
                    RiceBall
                    wrote on last edited by
                    #14

                    @Devopia53
                    @Pradeep-P-N said in How to make a SVG at tab Widget ?:

                    @RiceBall
                    Add QT += svg in .pro file

                    Refer Rendering SVG Files

                    I try to fix it.
                    It almost pass all compile.
                    But it show "The process was ended forcefully."

                    0_1559620323037_03042452-0e97-4dab-a6a1-1262504f5a74-image.png

                    jsulmJ 1 Reply Last reply
                    0
                    • R RiceBall

                      @Devopia53
                      @Pradeep-P-N said in How to make a SVG at tab Widget ?:

                      @RiceBall
                      Add QT += svg in .pro file

                      Refer Rendering SVG Files

                      I try to fix it.
                      It almost pass all compile.
                      But it show "The process was ended forcefully."

                      0_1559620323037_03042452-0e97-4dab-a6a1-1262504f5a74-image.png

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

                      @RiceBall said in How to make a SVG at tab Widget ?:

                      But it show "The process was ended forcefully."

                      Please debug and tell us where exactly it crashes...

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

                      R 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @RiceBall said in How to make a SVG at tab Widget ?:

                        But it show "The process was ended forcefully."

                        Please debug and tell us where exactly it crashes...

                        R Offline
                        R Offline
                        RiceBall
                        wrote on last edited by
                        #16

                        @jsulm said in How to make a SVG at tab Widget ?:

                        @RiceBall said in How to make a SVG at tab Widget ?:

                        But it show "The process was ended forcefully."

                        Please debug and tell us where exactly it crashes...

                        0_1559624756167_f34fd6ad-a1f5-404d-9d56-098a782b78eb-image.png

                        jsulmJ 1 Reply Last reply
                        0
                        • R RiceBall

                          @jsulm said in How to make a SVG at tab Widget ?:

                          @RiceBall said in How to make a SVG at tab Widget ?:

                          But it show "The process was ended forcefully."

                          Please debug and tell us where exactly it crashes...

                          0_1559624756167_f34fd6ad-a1f5-404d-9d56-098a782b78eb-image.png

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

                          @RiceBall Please show the whole content of your MainWindow constructor, especially line 31.
                          I guess it is the one you posted in a screen-shot before? It would be helpful if you would simply copy/paste the code instead of posting screen-shots.
                          It looks like your scene was not yet initialised.

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

                          R 1 Reply Last reply
                          1
                          • jsulmJ jsulm

                            @RiceBall Please show the whole content of your MainWindow constructor, especially line 31.
                            I guess it is the one you posted in a screen-shot before? It would be helpful if you would simply copy/paste the code instead of posting screen-shots.
                            It looks like your scene was not yet initialised.

                            R Offline
                            R Offline
                            RiceBall
                            wrote on last edited by
                            #18

                            @jsulm said in How to make a SVG at tab Widget ?:

                            @RiceBall Please show the whole content of your MainWindow constructor, especially line 31.
                            I guess it is the one you posted in a screen-shot before? It would be helpful if you would simply copy/paste the code instead of posting screen-shots.
                            It looks like your scene was not yet initialised.

                            I tried to simple it.
                            But the problem is the same.

                            .
                            mainwindow.cpp

                            #include "mainwindow.h"
                            #include "ui_mainwindow.h"
                            #include <QtGlobal>
                            #include <QMovie>
                            #include <QSvgWidget>
                            #include <QPixmap>
                            #include <QGraphicsScene>
                            #include <QGraphicsPixmapItem>
                            #include <QGraphicsView>
                            
                            MainWindow::MainWindow(QWidget *parent) :
                                QMainWindow(parent),
                                ui(new Ui::MainWindow)
                            {
                                ui->setupUi(this);
                            
                               ui->graphicsView->scene()->addWidget(new QSvgWidget("../untitled6/splash1.svg"));
                            
                            }
                            
                            MainWindow::~MainWindow()
                            {
                                delete ui;
                            }
                            
                            
                            jsulmJ 1 Reply Last reply
                            0
                            • R RiceBall

                              @jsulm said in How to make a SVG at tab Widget ?:

                              @RiceBall Please show the whole content of your MainWindow constructor, especially line 31.
                              I guess it is the one you posted in a screen-shot before? It would be helpful if you would simply copy/paste the code instead of posting screen-shots.
                              It looks like your scene was not yet initialised.

                              I tried to simple it.
                              But the problem is the same.

                              .
                              mainwindow.cpp

                              #include "mainwindow.h"
                              #include "ui_mainwindow.h"
                              #include <QtGlobal>
                              #include <QMovie>
                              #include <QSvgWidget>
                              #include <QPixmap>
                              #include <QGraphicsScene>
                              #include <QGraphicsPixmapItem>
                              #include <QGraphicsView>
                              
                              MainWindow::MainWindow(QWidget *parent) :
                                  QMainWindow(parent),
                                  ui(new Ui::MainWindow)
                              {
                                  ui->setupUi(this);
                              
                                 ui->graphicsView->scene()->addWidget(new QSvgWidget("../untitled6/splash1.svg"));
                              
                              }
                              
                              MainWindow::~MainWindow()
                              {
                                  delete ui;
                              }
                              
                              
                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #19

                              @RiceBall Did you set the scene?
                              https://doc.qt.io/qt-5/qgraphicsview.html#setScene

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

                              R 1 Reply Last reply
                              2
                              • jsulmJ jsulm

                                @RiceBall Did you set the scene?
                                https://doc.qt.io/qt-5/qgraphicsview.html#setScene

                                R Offline
                                R Offline
                                RiceBall
                                wrote on last edited by RiceBall
                                #20

                                @jsulm said in How to make a SVG at tab Widget ?:

                                @RiceBall Did you set the scene?
                                https://doc.qt.io/qt-5/qgraphicsview.html#setScene

                                No.I don't set any scene.
                                Should I need to set it by " QGraphicsScene scene " at mainwindow.cpp ??? Or Not ?

                                jsulmJ 1 Reply Last reply
                                0
                                • R RiceBall

                                  @jsulm said in How to make a SVG at tab Widget ?:

                                  @RiceBall Did you set the scene?
                                  https://doc.qt.io/qt-5/qgraphicsview.html#setScene

                                  No.I don't set any scene.
                                  Should I need to set it by " QGraphicsScene scene " at mainwindow.cpp ??? Or Not ?

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

                                  @RiceBall Well https://doc.qt.io/qt-5/qgraphicsview.html#scene says
                                  "Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned."
                                  I would say you have to set a scene as shown here https://doc.qt.io/qt-5/qgraphicsview.html

                                  QGraphicsScene scene;
                                  scene.addText("Hello, world!");
                                  
                                  QGraphicsView view(&scene); // use setScene() instead
                                  view.show();
                                  

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

                                  R 1 Reply Last reply
                                  3
                                  • jsulmJ jsulm

                                    @RiceBall Well https://doc.qt.io/qt-5/qgraphicsview.html#scene says
                                    "Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned."
                                    I would say you have to set a scene as shown here https://doc.qt.io/qt-5/qgraphicsview.html

                                    QGraphicsScene scene;
                                    scene.addText("Hello, world!");
                                    
                                    QGraphicsView view(&scene); // use setScene() instead
                                    view.show();
                                    
                                    R Offline
                                    R Offline
                                    RiceBall
                                    wrote on last edited by
                                    #22

                                    @jsulm said in How to make a SVG at tab Widget ?:

                                    @RiceBall Well https://doc.qt.io/qt-5/qgraphicsview.html#scene says
                                    "Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned."
                                    I would say you have to set a scene as shown here https://doc.qt.io/qt-5/qgraphicsview.html

                                    QGraphicsScene scene;
                                    scene.addText("Hello, world!");
                                    
                                    QGraphicsView view(&scene); // use setScene() instead
                                    view.show();
                                    

                                    I try to fix it as your recommend.
                                    But it will shown "no viable conversion from 'QGraphicsScene' to ' QGraphicsScene *'"
                                    Where should I need to change ?

                                    0_1559628266061_8753d00e-b560-4a5b-ae3b-0abf8566b31e-image.png

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • Pradeep P NP Offline
                                      Pradeep P NP Offline
                                      Pradeep P N
                                      wrote on last edited by Pradeep P N
                                      #23

                                      @RiceBall said in How to make a SVG at tab Widget ?:

                                      'QGraphicsScene' to ' QGraphicsScene *'"

                                      Please try ui->graphicView->setScene(&scene);

                                      Pradeep Nimbalkar.
                                      Upvote the answer(s) that helped you to solve the issue...
                                      Keep code clean.

                                      R 1 Reply Last reply
                                      3
                                      • mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #24

                                        Hi
                                        Please notice you are killing the scene very fast.
                                        Make it a member of the class.
                                        Should live in class so it dont go out of scope,

                                        1 Reply Last reply
                                        3
                                        • R RiceBall

                                          @jsulm said in How to make a SVG at tab Widget ?:

                                          @RiceBall Well https://doc.qt.io/qt-5/qgraphicsview.html#scene says
                                          "Returns a pointer to the scene that is currently visualized in the view. If no scene is currently visualized, 0 is returned."
                                          I would say you have to set a scene as shown here https://doc.qt.io/qt-5/qgraphicsview.html

                                          QGraphicsScene scene;
                                          scene.addText("Hello, world!");
                                          
                                          QGraphicsView view(&scene); // use setScene() instead
                                          view.show();
                                          

                                          I try to fix it as your recommend.
                                          But it will shown "no viable conversion from 'QGraphicsScene' to ' QGraphicsScene *'"
                                          Where should I need to change ?

                                          0_1559628266061_8753d00e-b560-4a5b-ae3b-0abf8566b31e-image.png

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

                                          @RiceBall Please think about what you're doing instead of blindly copy/paste code snippets which meant to be simple examples.
                                          First: don't create the scene on the stack!
                                          Second: pass pointer to setScene (the error message actually tells you what is wrong).

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

                                          1 Reply Last reply
                                          4

                                          • Login

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