Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 如何在QGraphics View中加入SVG檔案
Qt 6.11 is out! See what's new in the release blog

如何在QGraphics View中加入SVG檔案

Scheduled Pinned Locked Moved Unsolved Chinese
3 Posts 1 Posters 1.5k 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.
  • R Offline
    R Offline
    RiceBall
    wrote on last edited by RiceBall
    #1

    大家好,我是個新手
    我想請問一下,我想寫一個可以多重載入動態的SVG檔案的視窗
    以下是我的CODE

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

    我只瞬間看得他閃了一下就消失了,請問是哪裡出現問題嗎??

    還有,如果我要是在UI中使用Graphic View ,我該怎麼把新增的圖片(SVG)載入至此呢??

    以下是我的附件,可以給我個方向嗎???謝謝
    https://drive.google.com/open?id=17mOeeA11xWIo17LzSuDw6pcf9QvLePnH

    R 1 Reply Last reply
    0
    • R RiceBall

      大家好,我是個新手
      我想請問一下,我想寫一個可以多重載入動態的SVG檔案的視窗
      以下是我的CODE

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

      我只瞬間看得他閃了一下就消失了,請問是哪裡出現問題嗎??

      還有,如果我要是在UI中使用Graphic View ,我該怎麼把新增的圖片(SVG)載入至此呢??

      以下是我的附件,可以給我個方向嗎???謝謝
      https://drive.google.com/open?id=17mOeeA11xWIo17LzSuDw6pcf9QvLePnH

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

      @RiceBall said in 如何在QGraphics View中加入SVG檔案:

      大家好,我是個新手
      我想請問一下,我想寫一個可以多重載入動態的SVG檔案的視窗
      以下是我的CODE

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

      我只瞬間看得他閃了一下就消失了,請問是哪裡出現問題嗎??

      還有,如果我要是在UI中使用Graphic View ,我該怎麼把新增的圖片(SVG)載入至此呢??

      以下是我的附件,可以給我個方向嗎???謝謝
      https://drive.google.com/open?id=17mOeeA11xWIo17LzSuDw6pcf9QvLePnH

      有人已經建議我將以下刪除
      QGraphicsView view(scene);
      view.show();

      改成ui->graphicsView->setScene(scene);
      看起來有載入某些東西沒錯,但目前還是卡在,圖形載入後瞬間消失的問題
      請神人再幫我看一下如何解決,謝謝

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RiceBall
        wrote on last edited by
        #3

        這網站好像沒什麼人在回覆喔??

        我找到人幫我解答,大家參考看看吧!!

            QGraphicsScene *scene = new QGraphicsScene;
            scene->addWidget(new QSvgWidget("../untitled6/splash1.svg"));
            scene->addWidget(new QSvgWidget("../untitled6/splash2.svg"));
        
            ui->graphicsView->setScene(scene);
        

        看大家能不能繼續解答下去,我要如何將載入的svg檔案,定義尺寸大小與去除背景色(原檔是無底色)

        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