Qt5 怎么能让一个窗口保持在最前端,即Always on Top

oqzuser090 2014-05-19 09:59:16
this->setWindowsFlags(Qt::WindowStaysOnTopHint)是没有用的,调用它后,只会把窗口隐藏。麻烦各位大神指点一二。
...全文
7778 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
BA戒 2018-05-29
  • 打赏
  • 举报
回复
虽然用了show,但是窗口会闪一下,感觉不太好
「已注销」 2016-11-29
  • 打赏
  • 举报
回复
有窗口抖动 如何消除?
oqzuser090 2014-05-26
  • 打赏
  • 举报
回复
引用 11 楼 oqzuser090 的回复:
void MainWindow::on_AlwaysOnTop_clicked() { if (_alwaysOnTop->isChecked() == true) { this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); this->show(); } else if (_alwaysOnTop->isChecked() == false){ this->setWindowFlags(this->windowFlags() &~ Qt::WindowStaysOnTopHint); } } 执行之后,窗口缩小到托盘里了!即使在else里加入this->show();,就形成true的状态。求助啊、
在Mac里,如下,是好用的,我怀疑是Windows上的Qt本身的问题 void MainWindow::on_AlwaysOnTop_clicked() { if (_alwaysOnTop->isChecked() == true) { this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); this->show(); } else if (_alwaysOnTop->isChecked() == false){ this->setWindowFlags(this->windowFlags() &~ Qt::WindowStaysOnTopHint); this->show(); } }
zpf82118 2014-05-20
  • 打赏
  • 举报
回复
调用完setWindowsFlags后,需要show一下
oqzuser090 2014-05-20
  • 打赏
  • 举报
回复
void MainWindow::on_AlwaysOnTop_clicked() { if (_alwaysOnTop->isChecked() == true) { this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); this->show(); } else if (_alwaysOnTop->isChecked() == false){ this->setWindowFlags(this->windowFlags() &~ Qt::WindowStaysOnTopHint); } } 执行之后,窗口缩小到托盘里了!即使在else里加入this->show();,就形成true的状态。求助啊、
赵4老师 2014-05-19
  • 打赏
  • 举报
回复
传说中Qt是开源的。 Topmost Windows A topmost window is a window that has the WS_EX_TOPMOST style. Topmost windows are above all non-topmost sibling windows in the Z order. You can create a topmost window directly by specifying the WS_EX_TOPMOST style when you create the window. You can also make a window a topmost window by calling the SetWindowPos function and setting the hWndInsertAfter parameter to HWND_TOPMOST. A window may lose its topmost style by calling SetWindowPos and setting the hWndInsertAfter parameter to HWND_NOTOPMOST. If a window is positioned directly after a non-topmost window, then that window loses its WS_EX_TOPMOST style. Do not confuse topmost with top-level. Top-level refers to whether or not a window has a parent, whereas topmost refers to a specific style that controls the Z order for the window. You can set the SetWindowLong function to give a the window the WS_EX_TOPMOST style. However, this function does not change the windows Z order.
zhangwuji154 2014-05-19
  • 打赏
  • 举报
回复
http://www.qtcentre.org/threads/38414-window-setWindowsFlags(Qt-FramelessWindowHint)-and-setWindowOpacity(-8)-dont-work
赵4老师 2014-05-19
  • 打赏
  • 举报
回复
引用 7 楼 oqzuser090 的回复:
就是像你所说的,窗口显示出来了,在点击always on top 按钮,调用this->setWindowsFlags(Qt::WindowStaysOnTopHint);现在是好用了,但是取消不了了,怎么办?
我猜,你得: 点击always on top 按钮: this->setWindowsFlags(this->getWindowsFlags() | Qt::WindowStaysOnTopHint); 取消时: this->setWindowsFlags(this->getWindowsFlags() &~ Qt::WindowStaysOnTopHint);
oqzuser090 2014-05-19
  • 打赏
  • 举报
回复
引用 7 楼 oqzuser090 的回复:
就是像你所说的,窗口显示出来了,在点击always on top 按钮,调用this->setWindowsFlags(Qt::WindowStaysOnTopHint);现在是好用了,但是取消不了了,怎么办?

如下:
oqzuser090 2014-05-19
  • 打赏
  • 举报
回复
就是像你所说的,窗口显示出来了,在点击always on top 按钮,调用this->setWindowsFlags(Qt::WindowStaysOnTopHint);现在是好用了,但是取消不了了,怎么办?
赵4老师 2014-05-19
  • 打赏
  • 举报
回复
引用 5 楼 oqzuser090 的回复:
this->setWindowsFlags(Qt::WindowStaysOnTopHint)在第一次调用时窗口隐藏了,再把窗口显示出来,点其他的窗口就好用了,这是怎么回事?
你为什么不在窗口每次显示出来后调用this->setWindowsFlags(Qt::WindowStaysOnTopHint)捏?
oqzuser090 2014-05-19
  • 打赏
  • 举报
回复
this->setWindowsFlags(Qt::WindowStaysOnTopHint)在第一次调用时窗口隐藏了,再把窗口显示出来,点其他的窗口就好用了,这是怎么回事?
oqzuser090 2014-05-19
  • 打赏
  • 举报
回复
引用 1 楼 zhangwuji154 的回复:
http://www.qtcentre.org/threads/38414-window-setWindowsFlags(Qt-FramelessWindowHint)-and-setWindowOpacity(-8)-dont-work
您给我的是设置窗口的透明度,跟我要的不符啊。
oqzuser090 2014-05-19
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
传说中Qt是开源的。 Topmost Windows A topmost window is a window that has the WS_EX_TOPMOST style. Topmost windows are above all non-topmost sibling windows in the Z order. You can create a topmost window directly by specifying the WS_EX_TOPMOST style when you create the window. You can also make a window a topmost window by calling the SetWindowPos function and setting the hWndInsertAfter parameter to HWND_TOPMOST. A window may lose its topmost style by calling SetWindowPos and setting the hWndInsertAfter parameter to HWND_NOTOPMOST. If a window is positioned directly after a non-topmost window, then that window loses its WS_EX_TOPMOST style. Do not confuse topmost with top-level. Top-level refers to whether or not a window has a parent, whereas topmost refers to a specific style that controls the Z order for the window. You can set the SetWindowLong function to give a the window the WS_EX_TOPMOST style. However, this function does not change the windows Z order.
没有您说的SetWindowPos function and hWndInsertAfter。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧