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
329 Bytes
Loading
134 Bytes
Loading
2.61 KB
Loading
1.61 KB
Loading
256 Bytes
Loading
222 Bytes
Loading
994 Bytes
Loading
1.41 KB
Loading
483 Bytes
Loading
686 Bytes
Loading
493 Bytes
Loading
315 Bytes
Loading
2.84 KB
Loading
569 Bytes
Loading
498 Bytes
Loading
976 Bytes
Loading
332 Bytes
Loading
216 Bytes
Loading

qt_screenshot/resources/res.qrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<RCC>
2+
<qresource prefix="/"/>
3+
<qresource prefix="/icons">
4+
<file>icon/bug-check.png</file>
5+
<file>icon/bug-uncheck.png</file>
6+
<file>icon/cbx-down.png</file>
7+
<file>icon/check.png</file>
8+
<file>icon/close_button.png</file>
9+
<file>icon/cross32.png</file>
10+
<file>icon/demand-check.png</file>
11+
<file>icon/demand-uncheck.png</file>
12+
<file>icon/down-arrow.png</file>
13+
<file>icon/dropdown.png</file>
14+
<file>icon/failed-tip.png</file>
15+
<file>icon/item-default.png</file>
16+
<file>icon/menu-exit.png</file>
17+
<file>icon/menu-setting.png</file>
18+
<file>icon/menu-shot.png</file>
19+
<file>icon/menu-ztsetting.png</file>
20+
<file>icon/mosaic.png</file>
21+
<file>icon/new-item.png</file>
22+
<file>icon/remove-item.png</file>
23+
<file>icon/success-tip.png</file>
24+
<file>icon/uncheck.png</file>
25+
<file>icon/up-arrow.png</file>
26+
</qresource>
27+
</RCC>

0 commit comments

Comments
 (0)