I have this code, which shows a blank widget!
:confused:
Code:
{ toolButton->setIcon (*newTabIcon); mainSplitter->addWidget(toolButton); }
Is this the right way to use SVGs in qt 4.1.1?
Printable View
I have this code, which shows a blank widget!
:confused:
Code:
{ toolButton->setIcon (*newTabIcon); mainSplitter->addWidget(toolButton); }
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.
Thanks; I did, but it was rather complex for a QT newbie like me. Besides, it uses custom widgets.Quote:
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
Remember to add "QT += svg" to your .pro file..
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); }
Edit: Btw, I did not test above code. Oh, and you might want to initialize the svg renderer somewhere else.. :p
A bit more complex but definitely more elegant way would be to implement a QIconEnginePlugin.
Quote:
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.
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).Quote:
Originally Posted by jpn
Code:
{ painter.setBackgroundMode(Qt::OpaqueMode); renderer.render (&painter); toolButton->setIcon (newTabIcon); tabs.setCornerWidget (toolButton, Qt::BottomLeftCorner); }