Qt什么时候用activateWindow

     阅读(203)  2019-03-05 17:00:48

Qt什么时候用activateWindow

通常我们使用show来显示窗口,使用raise将窗口显示在最前面。
遇到的问题是,当在主窗口中打开一个子窗口时,如果这个窗口之前已经创建好了,它只是不在最前面被遮挡了,这时候要把它显示在前面使用show和raise是可以的。但是会带来一个问题,如果在当前窗口上没有做任何操作就直接点击主窗口,此时子窗口还是在前面,遮挡住了主窗口。除非你在子窗口上点击一下再点击主窗口就可以了。

解决上面问题的方法其实就是使用activateWindow和raise。

可以参考下面的API解释。

void QWidget::show()

Shows the widget and its child widgets. This is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true), depending on the platform's default behavior for the window flags.

void QWidget::showNormal()

Restores the widget after it has been maximized or minimized. Calling this function only affects windows.

void 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.

void QWidget::activateWindow()

Sets the top-level widget containing this widget to be the active window. An active window is a visible top-level window that has the keyboard input focus. This function performs the same operation as clicking the mouse on the title bar of a top-level window. On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well you should also call raise(). Note that the window must be visible, otherwise activateWindow() has no effect. On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window. It will change the color of the taskbar entry to indicate that the window has changed in some way. This is because Microsoft does not allow an application to interrupt what the user is currently doing in another application.

文章评论

Keep it simple,stupid
文章数
290
总访问量
305775
今日访问
418
最近评论

xuehaoyun : 很不错,来围观一下
tujiaw : 抱歉csdn code服务关闭了,这个代码我也找不到了
于淞 : 你好,这个文章的源码能分享一下吗,songsong9181@163.com,谢谢了 上面的写错了
于淞 : 你好,这个文章的源码能分享一下吗,838106303@163.com,谢谢了 上面的链接不能用了
tujiaw : 多谢多谢
essaypinglun college-paper.org : 很好的博客,赞赞
Folly : 这个实现有点奇怪,Qt为什么没有统一的比对方法。
过多s : alert("hello, world!")
tujiaw : 还不错哦
回到顶部