tags:

views:

474

answers:

2

Hello.

I have tried to create a custom-painted icon using QT under window. The following code displays an icon, but it looks transparent instead of color filled :(. OS is WinXP SP3, IDE is latest QTCreator.

int main( int argc, char* argv[] )
{
  QApplication oApp( argc, argv );

  QImage oImg( 16, 16, QImage::Format_RGB32 );
  oImg.fill( qRgb( 255, 0, 255 ) );
  QPixmap oPixmap;
  oPixmap.fromImage( oImg, Qt::ColorOnly );
  QIcon oIcon( oPixmap );
  QSystemTrayIcon oTrayIcon( oIcon );
  oTrayIcon.show();

  return oApp.exec();
}
+1  A: 

I couldn't figure out why, but if you save oImg to a file, you can see that the image is not filled. But if you fill QPixmap directly instead of oImg you can see the icon.

int main( int argc, char* argv[] )
{
    QApplication oApp( argc, argv );

    QPixmap oPixmap(16,16);
    oPixmap.fill(qRgb( 255, 0, 255 ));

    QIcon oIcon( oPixmap );
    QSystemTrayIcon oTrayIcon( oIcon );
    oTrayIcon.show();

    return oApp.exec();
}
erelender
Thanks :). QT documentation misguided me, telling that 'QPixmap is for usage, QImage is for modifications" :).
Eye of Hell
A: 

thank you. This post saved me asking similar question. acknowledge.

knishua