Qt中,保持窗口置頂的設置為:
Qt::WindowFlags m_flags = windowFlags();
setWindowFlags(m_flags | Qt::WindowStaysOnTopHint);
但是添加了這條語句后,窗口反而找不見了;
還要在下面添加一句:
show();
窗口就彈出來了,保持置頂;
想要取消置頂,方法如下:
m_flags = NULL;
setWindowFlags(m_flags);
show();
所以置頂與取消置頂的邏輯如下:
/// \brife 主窗口置頂 void OSGBTool::topMostSlot() { if (m_flags == NULL) { m_flags = windowFlags(); setWindowFlags(m_flags | Qt::WindowStaysOnTopHint); show(); } else { m_flags = NULL; setWindowFlags(m_flags); show(); } return; }
