zoukankan      html  css  js  c++  java
  • [Qt] 通过socket将另一个程序的某个窗口调到最前端

    @ // 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:

    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

  • 相关阅读:
    20210608日报
    数据结构-四则表达式运算
    软工博客归档工具(自用)
    阅读笔记6
    阅读笔记4
    阅读笔记3
    阅读笔记2
    阅读笔记5
    阅读笔记1
    大二下第16周总结
  • 原文地址:https://www.cnblogs.com/liujx2019/p/10696577.html
Copyright © 2011-2022 走看看