How would I go about making a overlay widget

人走茶凉 提交于 2021-02-11 13:01:42

问题


How would I go about making a overlay widget with qt?

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.


回答1:


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.

If you go with the second solution, you will have to play with the windows flags to make it borderless.

In both cases, you may have to use the raise() function to make sure your overlay widget is on top.

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.

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().



来源:https://stackoverflow.com/questions/56955960/how-would-i-go-about-making-a-overlay-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!