TrayIcon for Qt4

把最核心的帖在这里
//credit to Jason Stubbs @ qt-interest
static HICON createIcon( const QPixmap &pm, HBITMAP &hbm )
{
 ICONINFO iconInfo;
 iconInfo.fIcon    = TRUE;
 iconInfo.hbmMask  = hbm = pm.createMaskFromColor(Qt::black).toWinHBITMAP();
 iconInfo.hbmColor = pm.toWinHBITMAP(QPixmap::PremultipliedAlpha);
 HICON icon = CreateIconIndirect( &iconInfo );
 DeleteObject(iconInfo.hbmMask);
 iconInfo.hbmMask = hbm = 0; // michalj
 return icon;
}
发现一点小问题,在如下代码里:
void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
{
#ifdef Q_OS_WIN
// This is for Windows, where menus appear on mouse release
 switch ( e->button() ) {
  case Qt::RightButton:
   if ( pop ) {
    // Necessary to make keyboard focus
    // and menu closing work on Windows.
    pop->activateWindow();
    pop->exec( e->globalPos());
    pop->activateWindow();
    e->accept();
   }
   break;
   …
 }
#endif
 e->ignore();
}
pop->exec( e->globalPos()); 点在任务栏的system tray位置上,弹出来的菜单居然在任务栏上沿,而不是从鼠标点的位置上弹出。如图比较了 msn弹出菜单和这个system tray弹出菜单。看了一下QMenu源码,好象是Qt专门做的,但好象就不是那么native的感觉了。红点是鼠标点的位置。
不知道有没有人有workaround?
 

1 thought on “TrayIcon for Qt4

Leave a Reply

Your email address will not be published.