Qt 窗口置顶和取消置顶

//使用setWindowFlags()
void Widget::on_pushButton_topHint_clicked()
{
    this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
    this->show();
}

void Widget::on_pushButton_cancelTopHint_clicked()
{
    this->setWindowFlags(this->windowFlags() & ~Qt::WindowStaysOnTopHint);
    this->show();
}

//使用setWindowFlag()
//void Widget::on_pushButton_topHint_clicked()
//{
//    bool wasMaximized = this->isMaximized();
//    this->setWindowFlag(Qt::WindowStaysOnTopHint, true);
//    this->show();
    if (wasMaximized)
    {
        this->showMaximized();
    }
//}

//void Widget::on_pushButton_cancelTopHint_clicked()
//{
//    bool wasMaximized = this->isMaximized();
//    this->setWindowFlag(Qt::WindowStaysOnTopHint, false);
//    this->show();
    if (wasMaximized)
    {
        this->showMaximized();
    }
//}

你可能感兴趣的:(Qt,编程,qt,c++)