Results 1 to 6 of 6

Thread: Setting window icon on derived QWidget

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

    Default Setting window icon on derived QWidget

    Hi,

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

    This is the code I have to set the icon :

    Qt Code:
    1. setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/car.png")));
    To copy to clipboard, switch view to plain text mode 

    But alas, I still have the default QT icon?

    Any help is appreciated,

    Steve

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Setting window icon on derived QWidget

    setWindowIcon(QIcon(":/images/VDB_Logo.png")); this code working for me.
    you try this
    setWindowIcon(QIcon(":/QTCanMonitor/Resources/car.png"));
    make sure your icon is there.


  3. #3
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting window icon on derived QWidget

    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 :

    Qt Code:
    1. m_pworkspace->addSubWindow( m_pPlotterView );
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting window icon on derived QWidget

    Qt Code:
    1. QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( m_pPlotterView );
    2. subWindow->setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/car.png")));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    steg90 (16th July 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting window icon on derived QWidget

    • 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... ).
    • Is your widget a window (i.e a top level one, either main window, a dialog or a mdi sub window...)
    Current Qt projects : QCodeEdit, RotiDeCode

  7. #6
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting window icon on derived QWidget

    Thanks all,

    JPN's solution worked a treat

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.