简体   繁体   English

其他非qt窗口顶部的Qt小部件

[英]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. 我正在为Windows操作系统中使用的商业程序(无法更改)开发插件。 In this plugin I create a Qt Widget and when in the main program a button is clicked, the qt widget appears. 在此插件中,我创建了一个Qt小部件,然后在主程序中单击按钮时,将显示qt小部件。

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. Qt :: WindowStaysOnTopHint似乎在这里不起作用,因为我没有Qt父母。

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: 我找到了一种将其放在Qt Wiki之后的顶部的方法,并且创建了一个在小部件构造函数之后调用的方法:

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. 在小部件内,我无法使用某些QPushButton,如果引发窗口,则无法单击它们。 clicked() signals are not captured and button image does not change when I click on it with mouse. 当我用鼠标单击时,不会捕获clicked()信号,按钮图像也不会更改。
  • Inside the widget I use a derived QGLWidget derived class. 在小部件内部,我使用派生的QGLWidget派生类。 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? 我怎样才能正确地举起QWidget?

Before using your hack, check if widget->window()->raise() wouldn't work. 在使用您的hack之前,请检查widget->window()->raise()是否不起作用。

Using the window class "#32770" is an error. 使用窗口类“#32770”是错误。 You need to use the same window class that Qt is already using for your window. 您需要使用与Qt已经用于您的窗口的相同窗口类。

You need to retrieve the class used by Qt for the existing window, and only then create a new window with the same class. 您需要检索Qt用于现有窗口的类,然后才使用相同的类创建一个新窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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