Results 1 to 7 of 7

Thread: svg icons not showing up

  1. #1
    Join Date
    Mar 2006
    Location
    India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question svg icons not showing up

    I have this code, which shows a blank widget!


    Qt Code:
    1. {
    2. QToolButton *toolButton = new QToolButton(0);
    3. QIcon *newTabIcon = new QIcon("newTab.svg");
    4. toolButton->setIcon (*newTabIcon);
    5. mainSplitter->addWidget(toolButton);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Is this the right way to use SVGs in qt 4.1.1?
    Qt 4.2 (qt-copy in KDE svn)
    KDE 4.0 (svn)
    Currently developing Anthias

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: svg icons not showing up

    It's not the right way to use SVG files, see QtSvg Module documentation.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Location
    India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: svg icons not showing up

    Quote Originally Posted by jpn
    It's not the right way to use SVG files, see QtSvg Module documentation.
    Thanks; I did, but it was rather complex for a QT newbie like me. Besides, it uses custom widgets.

    Isn't it possible to use svg with default widgets which support pixmaps?
    Qt 4.2 (qt-copy in KDE svn)
    KDE 4.0 (svn)
    Currently developing Anthias

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: svg icons not showing up

    I think that svg format has some another task for using
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: svg icons not showing up

    Remember to add "QT += svg" to your .pro file..

    Qt Code:
    1. #include <QSvgRenderer>
    2.  
    3. void SvgToolButton::paintEvent(QPaintEvent* e)
    4. {
    5. // allow button to paint it's borders..
    6. QToolButton::paintEvent(e);
    7. // buffer is a member variable of type QPixmap
    8. if (buffer.isNull() || buffer.size() != size() - margin)
    9. {
    10. // margin is a member variable of type QSize
    11. buffer = QPixmap(size() - margin);
    12. QString fileName("button.svg");
    13. QSvgRenderer renderer(fileName);
    14. QPainter painter(&buffer);
    15. renderer.render(&painter);
    16. }
    17. // draw a pixmap on the button
    18. QPainter painter(this);
    19. painter.drawPixmap(margin.height()/2, margin.width()/2, buffer);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Edit: Btw, I did not test above code. Oh, and you might want to initialize the svg renderer somewhere else..
    Last edited by jpn; 6th April 2006 at 14:59.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    ePharaoh (6th April 2006)

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: svg icons not showing up

    A bit more complex but definitely more elegant way would be to implement a QIconEnginePlugin.
    From QIcon docs:
    With QIconEnginePlugin it is possible to register different icon engines for different file suffixes, so you could provide a SVG icon engine or any other scalable format.
    J-P Nurmi

  8. #7
    Join Date
    Mar 2006
    Location
    India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: svg icons not showing up

    Quote Originally Posted by jpn
    A bit more complex but definitely more elegant way would be to implement a QIconEnginePlugin.
    Thanks for the leads, jpn. This is what I finally implemented, and I think it is elegant enough (posting here for the benefit of future noobs).

    Qt Code:
    1. {
    2. QToolButton *toolButton = new QToolButton(0);
    3.  
    4. QPixmap pixmap(24, 24);
    5. QPainter painter(&pixmap);
    6. painter.setBackgroundMode(Qt::OpaqueMode);
    7. QSvgRenderer renderer (QString("newTab.svg"));
    8. renderer.render (&painter);
    9. QIcon newTabIcon(pixmap);
    10.  
    11. toolButton->setIcon (newTabIcon);
    12. toolButton->setIconSize (QSize(24,24));
    13. tabs.setCornerWidget (toolButton, Qt::BottomLeftCorner);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Qt 4.2 (qt-copy in KDE svn)
    KDE 4.0 (svn)
    Currently developing Anthias

Similar Threads

  1. no icons on the another machine (after installation)
    By roxton in forum Installation and Deployment
    Replies: 2
    Last Post: 4th July 2008, 17:24
  2. about qt/embedded widgets showing in ARM platform
    By xianshuiren in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd December 2007, 05:48
  3. QIcon Icons are not visible
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2007, 19:11
  4. Facing problem with tool bar icons
    By jnana in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 08:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.