Qt-Qt之setApplicationDisplayName的使用(窗口标题栏批量增加后缀)

代码下载:
https://download.csdn.net/download/zhujianqiangqq/92485133 【免费】Qt之setApplicationDisplayName的使用(窗口标题栏批量增加后缀)资源-CSDN下载
代码实例:
DisPlayName.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
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 a.setApplicationDisplayName("zhujq"); 9 MainWindow w; 10 w.show(); 11 return a.exec(); 12 }
mainwindow.h
1 #ifndef MAINWINDOW_H 2 #define MAINWINDOW_H 3 4 #include <QMainWindow> 5 #include <QDialog> 6 7 QT_BEGIN_NAMESPACE 8 namespace Ui { class MainWindow; } 9 QT_END_NAMESPACE 10 11 12 class TMyTest : public QDialog 13 { 14 Q_OBJECT 15 public: 16 TMyTest(QWidget *parent = nullptr); 17 private: 18 }; 19 20 class MainWindow : public QMainWindow 21 { 22 Q_OBJECT 23 24 public: 25 MainWindow(QWidget *parent = nullptr); 26 ~MainWindow(); 27 28 private: 29 Ui::MainWindow *ui; 30 TMyTest *mTMyTest = nullptr; 31 }; 32 #endif // MAINWINDOW_H
mainwindow.cpp
1 #include "mainwindow.h" 2 #include "ui_mainwindow.h" 3 4 MainWindow::MainWindow(QWidget *parent) 5 : QMainWindow(parent) 6 , ui(new Ui::MainWindow) 7 { 8 ui->setupUi(this); 9 this->resize(400, 300); 10 11 mTMyTest = new TMyTest(this); 12 mTMyTest->show(); 13 } 14 15 MainWindow::~MainWindow() 16 { 17 delete ui; 18 } 19 20 21 TMyTest::TMyTest(QWidget *parent) 22 :QDialog(parent) 23 { 24 this->setWindowTitle("TMyTest"); 25 this->resize(300, 100); 26 }
mainwindow.ui
1 <?xml version="1.0" encoding="UTF-8"?> 2 <ui version="4.0"> 3 <class>MainWindow</class> 4 <widget class="QMainWindow" name="MainWindow"> 5 <property name="geometry"> 6 <rect> 7 <x>0</x> 8 <y>0</y> 9 <width>800</width> 10 <height>600</height> 11 </rect> 12 </property> 13 <property name="windowTitle"> 14 <string>MainWindow</string> 15 </property> 16 <widget class="QWidget" name="centralwidget"/> 17 <widget class="QMenuBar" name="menubar"/> 18 <widget class="QStatusBar" name="statusbar"/> 19 </widget> 20 <resources/> 21 <connections/> 22 </ui>
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我
浙公网安备 33010602011771号