Results 1 to 11 of 11

Thread: Winow's icon

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Winow's icon

    Hi. I've got a question. How to set window's (dialog's or mainwindow's) icon? Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Winow's icon

    Try QWidget::setWindowIcon().

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Winow's icon

    Like that?
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include "maker.h"
    4. #include "about.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication::setStyle ( new QPlastiqueStyle() );
    9. QApplication app(argc, argv);
    10. QWidget::setWindowIcon(QIcon (new.png));
    11. MainWindow MainWindow;
    12. MainWindow.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Winow's icon

    Don't forget the quotes around the file path. And beware of using relative paths.

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Winow's icon

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Winow's icon

    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?

  7. #7
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Winow's icon

    Yes, It doesn't. Of cource I read this message, but I don't understand what's this "without object" about

  8. #8
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Winow's icon

    So, what's the problem about? Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Winow's icon

    Quote Originally Posted by Salazaar View Post
    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().

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Winow's icon

    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 ??

  11. #11
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Winow's icon

    Yes, it's clear, thanks

Similar Threads

  1. QListWidget in ListMode - still has icon space
    By high_flyer in forum Newbie
    Replies: 10
    Last Post: 30th March 2007, 20:43
  2. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 20:17
  3. Showing Icon in vertical header of a table
    By vishal.chauhan in forum Qt Programming
    Replies: 7
    Last Post: 15th January 2007, 11:44
  4. set Icon to .app file
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 22:13
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 16:51

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.