简体   繁体   中英

Qt widget on top of other non qt window

I'm developing a plugin for a commercial program (I can't change it) that I use in Windows operating system. In this plugin I create a Qt Widget and when in the main program a button is clicked, the qt widget appears.

My problem is that the widget appears under the main program window, while I want it on top of it. It can be stay Always on top, if necessary.

Qt::WindowStaysOnTopHint does not seems to work here because I have no Qt parents.

I've found a way to put it on top, following the Qt wiki , and I've created a method that I call after widget constructor:

void RadiationPatternWidget::setWindowTopMost()
{
#ifdef Q_WS_WIN32
  HWND hwnd = winId();
  DWORD exStyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
  DWORD style   = ::GetWindowLong(hwnd, GWL_STYLE);

  HWND parent = NULL;
  if (parentWidget()) {
    parent = parentWidget()->winId();
  }
  exStyle |= WS_EX_TOPMOST;
  HWND newHwnd = ::CreateWindowEx(exStyle, L"#32770", NULL, style,
    CW_USEDEFAULT, CW_USEDEFAULT,
    CW_USEDEFAULT, CW_USEDEFAULT,
    parent, NULL, qWinAppInst(), NULL);
  create(newHwnd, true, true);
#endif // Q_WS_WIN32
}

Then I call it after constructor:

m_pxRadiationPatternWidget = new RadiationPatternWidget();
m_pxRadiationPatternWidget->setWindowTopMost();

Now it stays on top, but I've some problem:

  • Inside the widget I use some QPushButton cannot and if window is raised they are not clickable. clicked() signals are not captured and button image does not change when I click on it with mouse.
  • Inside the widget I use a derived QGLWidget derived class. When I put it on top this widget is black, while if I don't call the method it works well.

How can I raise on top che QWidget correctly?

Before using your hack, check if widget->window()->raise() wouldn't work.

Using the window class "#32770" is an error. You need to use the same window class that Qt is already using for your window.

You need to retrieve the class used by Qt for the existing window, and only then create a new window with the same class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM