PDA

View Full Version : Winow's icon



Salazaar
2nd June 2007, 22:03
Hi. I've got a question. How to set window's (dialog's or mainwindow's) icon? Regards

jacek
2nd June 2007, 22:06
Try QWidget::setWindowIcon().

Salazaar
2nd June 2007, 22:17
Like that?

#include <QApplication>
#include <QPlastiqueStyle>
#include "maker.h"
#include "about.h"

int main(int argc, char *argv[])
{
QApplication::setStyle ( new QPlastiqueStyle() );
QApplication app(argc, argv);
QWidget::setWindowIcon(QIcon (new.png));
MainWindow MainWindow;
MainWindow.show();
return app.exec();
}

wysota
2nd June 2007, 22:24
Don't forget the quotes around the file path. And beware of using relative paths.

Salazaar
2nd June 2007, 22:35
I have new.png in my resuorce file. But there's an error:
main.cpp:10:error: cannot call member function 'void QWidget::SetWindowIcon (const QIcon&) without object. I don't know what's this problem about, I have new.png in my resource file included in project. Regards

wysota
2nd June 2007, 22:39
setWindowIcon is not a static method. Call it as a regular method of your widget. Please read and try to understand the messages compiler gives you. It doesn't say anything about the icon, does it?

Salazaar
2nd June 2007, 22:42
Yes, It doesn't. Of cource I read this message, but I don't understand what's this "without object" about

Salazaar
2nd June 2007, 22:57
So, what's the problem about? Regards

jacek
2nd June 2007, 23:11
Of cource I read this message, but I don't understand what's this "without object" about
You have to tell the compiler on which object you want to invoke the QWidget::setWindowIcon() method, just as you did with QWidget::show().

aamer4yu
3rd June 2007, 06:39
Yes, It doesn't. Of cource I read this message, but I don't understand what's this "without object" about
you are calling QWidget::setWindowIcon(QIcon (new.png));

while you should be calling -
someObject.setWindowIcon(QIcon (new.png));
or mainWindow.setWindowIcon(QIcon (new.png));

is that clear now ?? without object thing ??

Salazaar
3rd June 2007, 17:36
Yes, it's clear, thanks