I have this code, which shows a blank widget!
Qt Code:
{ toolButton->setIcon (*newTabIcon); mainSplitter->addWidget(toolButton); }To copy to clipboard, switch view to plain text mode
Is this the right way to use SVGs in qt 4.1.1?
I have this code, which shows a blank widget!
Qt Code:
{ toolButton->setIcon (*newTabIcon); mainSplitter->addWidget(toolButton); }To copy to clipboard, switch view to plain text mode
Is this the right way to use SVGs in qt 4.1.1?
It's not the right way to use SVG files, see QtSvg Module documentation.
J-P Nurmi
Thanks; I did, but it was rather complex for a QT newbie like me. Besides, it uses custom widgets.Originally Posted by jpn
Isn't it possible to use svg with default widgets which support pixmaps?
I think that svg format has some another task for using
a life without programming is like an empty bottle
Remember to add "QT += svg" to your .pro file..
Qt Code:
#include <QSvgRenderer> { // allow button to paint it's borders.. // buffer is a member variable of type QPixmap if (buffer.isNull() || buffer.size() != size() - margin) { // margin is a member variable of type QSize renderer.render(&painter); } // draw a pixmap on the button painter.drawPixmap(margin.height()/2, margin.width()/2, buffer); }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
ePharaoh (6th April 2006)
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
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).Originally Posted by jpn
Qt Code:
{ painter.setBackgroundMode(Qt::OpaqueMode); renderer.render (&painter); toolButton->setIcon (newTabIcon); tabs.setCornerWidget (toolButton, Qt::BottomLeftCorner); }To copy to clipboard, switch view to plain text mode
Bookmarks