简体   繁体   English

我将如何制作覆盖小部件

[英]How would I go about making a overlay widget

How would I go about making a overlay widget with qt? 如何使用qt制作覆盖小部件? 例

例子2

I've considered using a QPaintEvent or a QGraphicsScene, but I want to be able to add widgets and for the widget to not occupy space in a layout, causing other widgets to shift when the popup appears. 我已经考虑过使用QPaintEvent或QGraphicsScene,但是我希望能够添加小部件并使小部件不占用布局中的空间,从而导致其他小部件在出现弹出窗口时发生移动。

I believe the best solution is to parent the so called overlay widget to the window or even have the overlay widget be in its own window. 我相信最好的解决方案是将所谓的覆盖小部件作为窗口的父项,或者甚至将覆盖小部件置于其自己的窗口中。

The first solution might be easier to do, but the overlay widget is bound to the inside of the window. 第一个解决方案可能更容易实现,但是overlay小部件绑定到了窗口的内部。

If you go with the second solution, you will have to play with the windows flags to make it borderless. 如果采用第二种解决方案,则必须使用Windows标志使其无边界。

In both cases, you may have to use the raise() function to make sure your overlay widget is on top. 在这两种情况下,您可能都必须使用raise()函数来确保叠加窗口小部件位于顶部。

Discussing "using a QPaintEvent or a QGraphicsScene" is off-topic. 讨论“使用QPaintEvent或QGraphicsScene”是不合时宜的。 How you draw the widget does not impact how the widget will interact with the widget stack. 绘制小部件的方式不会影响小部件与小部件堆栈的交互方式。

If you want an example, you can take a look at the code of QCompleter which does something similar. 如果您想举个例子,您可以看一下QCompleter的代码,它的功能与此类似。 In particular look for QCompleter::setPopup() and QCompleterPrivate::showPopup() . 特别要QCompleter::setPopup()QCompleterPrivate::showPopup()

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

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