@ // THIS IS A HACK:
// from QT documentation:
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// void QWidget::activateWindow ()
// ...
// On Windows, if you are calling this when the application is not currently
// the active one then it will not make it the active window. It will change
// the color of the taskbar entry to indicate that the window has changed in
// some way. This is because Microsoft do not allow an application to
// interrupt what the user is currently doing in another application.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This hack does not give the focus to the app but brings it to front so
// the user sees it.
::SetWindowPos(effectiveWinId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
::SetWindowPos(effectiveWinId(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
// HACK END

In linux i use this:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
if(!this->isActiveWindow())
{   
this->setWindowFlags((windowFlags() & Qt::WindowStaysOnTopHint));   this->setWindowFlags((windowFlags() & ~Qt::WindowStaysOnTopHint));   this->show();
}

I use this in windows, it works

    Qt::WindowFlags flags = windowFlags();
    this->setWindowFlags((flags | Qt::WindowStaysOnTopHint));
    this->show();
    this->setWindowFlags(flags);
    this->show();

出处:https://forum.qt.io/topic/1939/activatewindow-does-not-send-window-to-front/11

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄