zoukankan      html  css  js  c++  java
  • Qt每3秒把程序最前显示一次,只是调整Z序列

    相关资料:

    https://www.bbsmax.com/A/l1dymbEbde/     Qt主窗体显示最前

    https://download.csdn.net/download/zhujianqiangqq/19821845    代码包下载

    实例:

    .pro

     1 QT       += core gui
     2 
     3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
     4 
     5 CONFIG += c++11
     6 
     7 # The following define makes your compiler emit warnings if you use
     8 # any Qt feature that has been marked deprecated (the exact warnings
     9 # depend on your compiler). Please consult the documentation of the
    10 # deprecated API in order to know how to port your code away from it.
    11 DEFINES += QT_DEPRECATED_WARNINGS
    12 
    13 # You can also make your code fail to compile if it uses deprecated APIs.
    14 # In order to do so, uncomment the following line.
    15 # You can also select to disable deprecated APIs only up to a certain version of Qt.
    16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    17 
    18 SOURCES += 
    19     main.cpp 
    20     mainwindow.cpp
    21 
    22 HEADERS += 
    23     mainwindow.h
    24 
    25 FORMS += 
    26     mainwindow.ui
    27 
    28 # Default rules for deployment.
    29 qnx: target.path = /tmp/$${TARGET}/bin
    30 else: unix:!android: target.path = /opt/$${TARGET}/bin
    31 !isEmpty(target.path): INSTALLS += target
    View Code

    main.cpp

     1 #include "mainwindow.h"
     2 
     3 #include <QApplication>
     4 
     5 int main(int argc, char *argv[])
     6 {
     7     QApplication a(argc, argv);
     8     MainWindow w;
     9     w.show();
    10     return a.exec();
    11 }
    View Code

    mainwindow.h

     1 #ifndef MAINWINDOW_H
     2 #define MAINWINDOW_H
     3 
     4 #include <QMainWindow>
     5 #include <QTimer>
     6 
     7 QT_BEGIN_NAMESPACE
     8 namespace Ui { class MainWindow; }
     9 QT_END_NAMESPACE
    10 
    11 class MainWindow : public QMainWindow
    12 {
    13     Q_OBJECT
    14 
    15 public:
    16     MainWindow(QWidget *parent = nullptr);
    17     ~MainWindow();
    18 
    19 private:
    20     void on_TimerEvent();
    21 
    22 private:
    23     Ui::MainWindow *ui;
    24     QTimer *m_pTimer = NULL;
    25 };
    26 #endif // MAINWINDOW_H
    View Code

    mainwindow.cpp

     1 #include "mainwindow.h"
     2 #include "ui_mainwindow.h"
     3 
     4 #ifdef Q_OS_WIN
     5 #pragma comment(lib, "user32.lib")
     6 #include <qt_windows.h>
     7 #endif
     8 
     9 MainWindow::MainWindow(QWidget *parent)
    10     : QMainWindow(parent)
    11     , ui(new Ui::MainWindow)
    12 {
    13     ui->setupUi(this);
    14 
    15     m_pTimer = new QTimer(this);
    16     m_pTimer->setSingleShot(false);
    17     m_pTimer->start(3000);// 每3秒后最新显示一次
    18     connect(m_pTimer, &QTimer::timeout, this, &MainWindow::on_TimerEvent);
    19 }
    20 
    21 MainWindow::~MainWindow()
    22 {
    23     delete ui;
    24 }
    25 
    26 void MainWindow::on_TimerEvent()
    27 {
    28     if (this->isMinimized())
    29     {
    30         this->showNormal();
    31     }
    32     // 设置窗口置顶
    33     ::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    34     // 恢复普通窗口
    35     ::SetWindowPos(HWND(this->winId()), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    36 
    37     this->show();
    38     this->activateWindow();
    39 }
    View Code
    作者:疯狂Delphi
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

    欢迎关注我,一起进步!扫描下方二维码即可加我

  • 相关阅读:
    python之路(三)-深浅拷贝
    Python之路(一)-python简介
    Web端裁剪图片方法
    如何将github上源代码导入eclipse中
    转 GitHub上史上最全的Android开源项目分类汇总
    转 GitHub上最火的40个Android开源项目(二)
    转 GitHub上最火的40个Android开源项目(一)
    转 GitHub上最火的74个Android开源项目(三)
    CSS实现文本溢出的部分用省略号代替的方法
    时尚且健壮: 实现更优秀的CSS
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/14930056.html
Copyright © 2011-2022 走看看