问题描述
我将如何使用 qt 制作覆盖小部件?
How would I go about making a overlay widget with qt?
我已经考虑使用 QPaintEvent 或 QGraphicsScene,但我希望能够添加小部件并且小部件不占用布局中的空间,从而导致其他小部件在弹出窗口出现时移动.
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.
推荐答案
我相信最好的解决方案是将所谓的覆盖小部件作为窗口的父级,或者甚至让覆盖小部件在它自己的窗口中.
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.
如果您采用第二种解决方案,则必须使用 Windows 标志使其无边框.
If you go with the second solution, you will have to play with the windows flags to make it borderless.
在这两种情况下,您可能都必须使用 raise()
函数来确保您的叠加小部件位于顶部.
In both cases, you may have to use the raise()
function to make sure your overlay widget is on top.
讨论使用 QPaintEvent 或 QGraphicsScene"是题外话.您绘制小部件的方式不会影响小部件与小部件堆栈交互的方式.
Discussing "using a QPaintEvent or a QGraphicsScene" is off-topic. How you draw the widget does not impact how the widget will interact with the widget stack.
如果你想要一个例子,你可以看看QCompleter
做了类似的事情.特别要查找 QCompleter::setPopup()
和 QCompleterPrivate::showPopup()
.
If you want an example, you can take a look at the code of QCompleter
which does something similar. In particular look for QCompleter::setPopup()
and QCompleterPrivate::showPopup()
.
这篇关于我将如何制作叠加小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!