C++ 如何在 Qt 中将 Widget 带到前面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3821743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Bring the Widget Bring to front in Qt?
提问by saravanan
Please have a look at this screenshot:
请看一下这个截图:
The circles are custom controls. When I click a control, I need to bring the widget to the front. Ex. if I click the second circle it should look like this:
圆圈是自定义控件。当我单击一个控件时,我需要将小部件放在最前面。前任。如果我点击第二个圆圈,它应该是这样的:
When the control is clicked I am able to get the sender (i.e. the control). Only thing is how to bring the object to the front.
单击控件时,我可以获取发送者(即控件)。唯一的问题是如何将对象带到前面。
Please help me fix this issue.
请帮我解决这个问题。
回答by the_mandrill
Have you tried QWidget::raise()?
你试过QWidget::raise()吗?
Raises this widget to the top of the parent widget's stack. After this call the widget will be visually in front of any overlapping sibling widgets.
Note: When using activateWindow(), you can call this function to ensure that the window is stacked on top.
将此小部件提升到父小部件堆栈的顶部。在此调用之后,小部件将在视觉上位于任何重叠的同级小部件之前。
注意:在使用 activateWindow() 时,您可以调用此函数以确保窗口堆叠在顶部。
So the pattern I usually use that will ensure a window is shown, brought to the front of sibling widgets and brought in front of other applications is:
所以我通常使用的模式将确保显示一个窗口,带到同级小部件的前面并带到其他应用程序的前面:
widget->show();
widget->activateWindow();
widget->raise();