PDA

View Full Version : Setting window icon on derived QWidget



steg90
16th July 2007, 10:56
Hi,

I'm struggling to set my window icon on a derived QWidget object.

This is the code I have to set the icon :



setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/car.png")));


But alas, I still have the default QT icon?

Any help is appreciated,

Steve

rajesh
16th July 2007, 11:00
setWindowIcon(QIcon(":/images/VDB_Logo.png")); this code working for me.
you try this
setWindowIcon(QIcon (http://doc.trolltech.com/4.2/QIcon.html)(":/QTCanMonitor/Resources/car.png"));
make sure your icon is there.

steg90
16th July 2007, 11:04
Still the same, the icon is there, but I still just get the default qt one.

Wondering if it could be something to with that the window is a sub-window? Code I use to add this to my mdi workspace :



m_pworkspace->addSubWindow( m_pPlotterView );


Where m_pPlotterView is my class derived from QWidget.

The only window I've successfully been able to change icon on is if it is derived from QDialog?

Regards,
Steve

jpn
16th July 2007, 11:15
QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( m_pPlotterView );
subWindow->setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/car.png")));

fullmetalcoder
16th July 2007, 11:15
Check out the case. AFAIK Qt resources paths are case-sensitive just like Unix (and unlike Window$ hence the troubles most users of that OS are facing with filenames... :rolleyes:).
Is your widget a window (i.e a top level one, either main window, a dialog or a mdi sub window...)

steg90
16th July 2007, 11:21
Thanks all,

JPN's solution worked a treat ;)