connect(ui->actionPin_to_top, &QAction::triggered, [&]() {
Qt::WindowFlags flags = this->windowFlags();
if (!isPintotop) {
this->setWindowFlags(flags | Qt::CustomizeWindowHint |
Qt::WindowStaysOnTopHint);
this->show();
} else {
this->setWindowFlags(
flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint));
this->show();
}
isPintotop = !isPintotop;
});
其中 ui->actionPin_to_top 是一个 QAction, isPintotop 是一个 bool 变量,用于记录当前是否已经 Pin to top 了。