Skip to content

Commit 1f2c15d

Browse files
Merge branch 'main' of github.com:zzu-andrew/QT_examples
2 parents eb6f0a6 + 1761962 commit 1f2c15d

File tree

10 files changed

+74
-202
lines changed

10 files changed

+74
-202
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/qt_screenshot/cmake-build-debug/

qt_screenshot/CMakeLists.txt.user

Lines changed: 18 additions & 152 deletions
Large diffs are not rendered by default.

qt_trayicon/fire.png

7.67 KB
Loading

qt_trayicon/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
int main(int argc, char *argv[])
55
{
66
QApplication a(argc, argv);
7-
MainWindow w;
8-
w.show();
7+
TrayIcon tray(&a);
8+
tray.show();
99

1010
return a.exec();
1111
}

qt_trayicon/mainwindow.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
#include "mainwindow.h"
2-
#include "ui_mainwindow.h"
32

4-
MainWindow::MainWindow(QWidget *parent) :
5-
QMainWindow(parent),
6-
ui(new Ui::MainWindow)
3+
#include <QMenu>
4+
#include <QSystemTrayIcon>
5+
6+
7+
TrayIcon::TrayIcon(QObject *parent) : QSystemTrayIcon(parent)
78
{
8-
ui->setupUi(this);
9-
}
9+
m_menu = new QMenu();
1010

11+
auto* captureAction = new QAction(tr("&Take Screenshot"), this);
1112

13+
auto* launcherAction = new QAction(tr("&Open Launcher"), this);
1214

15+
auto* configAction = new QAction(tr("&Configuration"), this);
1316

17+
auto* infoAction = new QAction(tr("&About"), this);
18+
19+
20+
QAction* quitAction = new QAction(tr("&Quit"), this);
21+
22+
// recent screenshots
23+
QAction* recentAction = new QAction(tr("&Latest Uploads"), this);
24+
25+
m_menu->addAction(captureAction);
26+
m_menu->addAction(launcherAction);
27+
m_menu->addSeparator();
28+
m_menu->addAction(recentAction);
29+
m_menu->addSeparator();
30+
m_menu->addAction(configAction);
31+
m_menu->addSeparator();
32+
33+
setToolTip(QStringLiteral("FireShot"));
34+
35+
setContextMenu(m_menu);
36+
QIcon icon = QIcon::fromTheme("flameshot-tray", QIcon(":/image/tv.png"));
37+
setIcon(icon);
1438

15-
MainWindow::~MainWindow()
16-
{
17-
delete ui;
1839
}
40+

qt_trayicon/mainwindow.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
#ifndef MAINWINDOW_H
2-
#define MAINWINDOW_H
1+
#include <QSystemTrayIcon>
32

4-
#include <QMainWindow>
3+
#pragma once
54

6-
namespace Ui {
7-
class MainWindow;
8-
}
5+
class QAction;
96

10-
class MainWindow : public QMainWindow
7+
class TrayIcon : public QSystemTrayIcon
118
{
129
Q_OBJECT
13-
1410
public:
15-
explicit MainWindow(QWidget *parent = nullptr);
16-
~MainWindow();
11+
explicit TrayIcon(QObject* parent);
12+
~TrayIcon() override = default;
13+
1714

1815
private:
19-
Ui::MainWindow *ui;
20-
};
16+
void initMenu();
2117

22-
#endif // MAINWINDOW_H
18+
static void startGuiCapture();
19+
20+
QMenu* m_menu;
21+
};

qt_trayicon/mainwindow.ui

Lines changed: 0 additions & 24 deletions
This file was deleted.

qt_trayicon/qt_trayicon.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ SOURCES += \
3131
HEADERS += \
3232
mainwindow.h
3333

34-
FORMS += \
35-
mainwindow.ui
34+
FORMS +=
3635

3736
# Default rules for deployment.
3837
qnx: target.path = /tmp/$${TARGET}/bin
3938
else: unix:!android: target.path = /opt/$${TARGET}/bin
4039
!isEmpty(target.path): INSTALLS += target
40+
41+
RESOURCES += \
42+
res.qrc

qt_trayicon/res.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/iamge">
3+
<file>tv.png</file>
4+
<file>fire.png</file>
5+
</qresource>
6+
</RCC>

qt_trayicon/tv.png

580 Bytes
Loading

0 commit comments

Comments
 (0)