0

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();
}
grigoryvp
  • 40,413
  • 64
  • 174
  • 277

1 Answers1

1

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
  • 6,175
  • 32
  • 49
  • Thanks :). QT documentation misguided me, telling that 'QPixmap is for usage, QImage is for modifications" :). – grigoryvp Oct 02 '09 at 08:08