QT 窗口置顶功能

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;
}

猜你喜欢

转载自www.cnblogs.com/ningmouming/p/9241968.html
今日推荐