Skip to content

Commit fead7d1

Browse files
添加资源文件
1 parent 655077b commit fead7d1

29 files changed

+446
-31
lines changed

qt_screenshot/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ add_executable(${PROJECT_NAME}
5252
fireshot.cpp
5353
${core_src}
5454
${utils_src}
55+
${CMAKE_CURRENT_SOURCE_DIR}/resources/res.qrc
5556
)
5657

5758

qt_screenshot/CMakeLists.txt.user

Lines changed: 385 additions & 0 deletions
Large diffs are not rendered by default.

qt_screenshot/fireshot.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44

55
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
66

7+
#include <QAction>
8+
79
#include "fireshot.h"
8-
#include "ui_mainwindow.h"
910
#include "utils/spdlog_wrapper.h"
1011

11-
FireShot::FireShot(QWidget *parent) :
12-
QMainWindow(parent), ui(new Ui::FireShot) {
13-
ui->setupUi(this);
12+
FireShot::FireShot(QWidget *parent) : QDialog(parent) {
13+
1414
}
1515

1616
FireShot::~FireShot() {
17-
delete ui;
1817
SPD_FLUSH();
1918
}
19+
int32_t FireShot::CreateActions() {
20+
21+
m_lpSettingAction = new QAction(tr("&Settings"), this);
22+
QIcon settingIcon(":/images/menu-setting.png");
23+
m_lpShotAction; // 截图按钮
24+
m_lpQuitAction; // 退出按钮
25+
26+
return 0;
27+
}
2028

qt_screenshot/fireshot.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@
55
#ifndef TEST_MAINWINDOW_H
66
#define TEST_MAINWINDOW_H
77

8-
#include <QMainWindow>
8+
#include <QDialog>
9+
#include <QSystemTrayIcon>
910

1011

11-
QT_BEGIN_NAMESPACE
12-
namespace Ui { class FireShot; }
13-
QT_END_NAMESPACE
14-
15-
class FireShot : public QMainWindow {
12+
class FireShot : public QDialog {
1613
Q_OBJECT
1714

1815
public:
1916
explicit FireShot(QWidget *parent = nullptr);
17+
int32_t CreateActions();
18+
2019

2120
~FireShot() override;
2221

2322
private:
24-
Ui::FireShot *ui;
23+
QSystemTrayIcon* m_lpTrayIcon; // 放置一个系统托盘图标
24+
QAction* m_lpSettingAction; // 系统托盘上的设置按钮
25+
QAction* m_lpShotAction; // 截图按钮
26+
QAction* m_lpQuitAction; // 退出按钮
27+
2528
};
2629

2730

qt_screenshot/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <QApplication>
22
#include <QPushButton>
3+
#include <QSystemTrayIcon>
34

45
#include "utils/spdlog_wrapper.h"
56
#include "fireshot.h"
@@ -13,6 +14,15 @@ int main(int argc, char *argv[]) {
1314
spdlog::SpdlogInit("FireShot", "logs/log.log", 23, 57, 0, 0);
1415
SPD_TRACE("start");
1516

17+
// 查看系统是否支持托盘功能
18+
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
19+
SPD_ERROR("system tray disabled");
20+
return 1;
21+
}
22+
23+
//设置系统默认字体
24+
QFont defaultFont("微软雅黑",9);
25+
QApplication::setFont(defaultFont);
1626

1727
QPushButton button("Hello world!", nullptr);
1828
button.resize(200, 100);

qt_screenshot/mainwindow.ui

Lines changed: 0 additions & 19 deletions
This file was deleted.
2.68 KB
Loading
1.7 KB
Loading
317 Bytes
Loading
552 Bytes
Loading

0 commit comments

Comments
 (0)