Qt 使一个窗口\部件始终显示在其它窗口之上

使用事件过滤器会导致只能和this窗口交互

可以采用以下方法,设置窗口标志

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGridLayout>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //this->installEventFilter(this);
    this->setWindowFlags(Qt::WindowStaysOnTopHint);
}

MainWindow::~MainWindow()
{
    delete ui;
}

//bool MainWindow::eventFilter(QObject *obj, QEvent *event)
//{
//    if(obj == this && event->type() == QEvent::WindowDeactivate)
//    {
//        activateWindow();
//    }
//}

效果:

可以看到form窗体为选中状态

猜你喜欢

转载自blog.csdn.net/TheKoi/article/details/124615876