Skip to content

Commit d8a4c73

Browse files
添加图标实现
1 parent 8dbd60b commit d8a4c73

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

qt_trayicon/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

qt_trayicon/mainwindow.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
10+
11+
12+
13+
14+
15+
MainWindow::~MainWindow()
16+
{
17+
delete ui;
18+
}

qt_trayicon/mainwindow.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
6+
namespace Ui {
7+
class MainWindow;
8+
}
9+
10+
class MainWindow : public QMainWindow
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit MainWindow(QWidget *parent = nullptr);
16+
~MainWindow();
17+
18+
private:
19+
Ui::MainWindow *ui;
20+
};
21+
22+
#endif // MAINWINDOW_H

qt_trayicon/mainwindow.ui

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<ui version="4.0">
2+
<class>MainWindow</class>
3+
<widget class="QMainWindow" name="MainWindow" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>400</width>
9+
<height>300</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>MainWindow</string>
14+
</property>
15+
<widget class="QMenuBar" name="menuBar" />
16+
<widget class="QToolBar" name="mainToolBar" />
17+
<widget class="QWidget" name="centralWidget" />
18+
<widget class="QStatusBar" name="statusBar" />
19+
</widget>
20+
<layoutDefault spacing="6" margin="11" />
21+
<pixmapfunction></pixmapfunction>
22+
<resources/>
23+
<connections/>
24+
</ui>

qt_trayicon/qt_trayicon.pro

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2023-10-14T09:24:24
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = qt_trayicon
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
CONFIG += c++11
26+
27+
SOURCES += \
28+
main.cpp \
29+
mainwindow.cpp
30+
31+
HEADERS += \
32+
mainwindow.h
33+
34+
FORMS += \
35+
mainwindow.ui
36+
37+
# Default rules for deployment.
38+
qnx: target.path = /tmp/$${TARGET}/bin
39+
else: unix:!android: target.path = /opt/$${TARGET}/bin
40+
!isEmpty(target.path): INSTALLS += target

0 commit comments

Comments
 (0)