How do I toggle 'always on top' for a QMainWindow in Qt without causing a flicker or a flash?

前端 未结 4 1091
猫巷女王i
猫巷女王i 2020-12-28 15:07
void MainWindow::on_actionAlways_on_Top_triggered(bool checked)
{
    Qt::WindowFlags flags = this->windowFlags();
    if (checked)
    {
        this->setWind         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 15:49

    Tested with

    • Qt 5.2.1 on windows XP
    • Qt 5.2 on OS X 10.9
    
        void ConsoleUI::onAllwaysTop(bool checked)
        {
            Qt::WindowFlags flags = windowFlags();
            if (checked)
            {
                flags ^= Qt::WindowStaysOnBottomHint;
                flags |= Qt::WindowStaysOnTopHint;
            }
            else
            {
                flags ^= Qt::WindowStaysOnTopHint;
                flags |= Qt::WindowStaysOnBottomHint;
            }
            setWindowFlags(flags);
            show();
        }
    
    

提交回复
热议问题