qt5 example
This commit is contained in:
parent
519053708d
commit
12c97ad421
1
projects/Qt/example/.clang-format
Symbolic link
1
projects/Qt/example/.clang-format
Symbolic link
@ -0,0 +1 @@
|
||||
../../../code/C++/.clang-format
|
11
projects/Qt/example/.gitignore
vendored
Normal file
11
projects/Qt/example/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# xmake
|
||||
.xmake/
|
||||
build/
|
||||
|
||||
# qmake
|
||||
.qmake.stash
|
||||
*.o
|
||||
moc_*.cpp
|
||||
moc_*.j
|
||||
moc_predefs.h
|
||||
Makefile
|
50
projects/Qt/example/README.md
Normal file
50
projects/Qt/example/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
## Темы
|
||||
|
||||
### qt5ct
|
||||
|
||||
```sh
|
||||
apt install qt5ct qt5-style-plugins
|
||||
```
|
||||
|
||||
```sh
|
||||
QT_QPA_PLATFORMTHEME=qt5ct xmake run
|
||||
```
|
||||
|
||||
Настройки осуществляются в приложении `qt5ct`
|
||||
|
||||
### Adwaita
|
||||
|
||||
Установить пакеты `adwaita-qt` и `adwaita-qt6`.
|
||||
|
||||
```sh
|
||||
apt install adwaita-qt adwaita-qt6
|
||||
```
|
||||
|
||||
Светлая тема
|
||||
|
||||
```sh
|
||||
# Светлая тема
|
||||
QT_STYLE_OVERRIDE=adwaita xmake run
|
||||
QT_STYLE_OVERRIDE=Adwaita xmake run
|
||||
```
|
||||
|
||||
Тёмная тема
|
||||
|
||||
```sh
|
||||
# Тёмная тема
|
||||
QT_STYLE_OVERRIDE=adwaita-dark xmake run
|
||||
QT_STYLE_OVERRIDE=Adwaita-dark xmake run
|
||||
```
|
||||
|
||||
## Другое
|
||||
|
||||
|
||||
```cpp
|
||||
/**
|
||||
* Available platform plugins are:
|
||||
* eglfs, linuxfb, minimal, minimalegl, offscreen, vnc,
|
||||
* wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb
|
||||
*/
|
||||
|
||||
qsetenv("QT_QPA_PLATFORM", "minimal").
|
||||
```
|
13
projects/Qt/example/hello.pro
Normal file
13
projects/Qt/example/hello.pro
Normal file
@ -0,0 +1,13 @@
|
||||
QT += core gui widgets
|
||||
CONFIG += c++17
|
||||
|
||||
INCLUDEPATH += include/ \
|
||||
|
||||
SOURCES += src/main.cpp \
|
||||
src/mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
include/mainwindow.hpp
|
||||
|
||||
DESTDIR = build
|
||||
TARGET = example
|
29
projects/Qt/example/include/mainwindow.hpp
Normal file
29
projects/Qt/example/include/mainwindow.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef MAINWINDOW_HPP
|
||||
#define MAINWINDOW_HPP
|
||||
|
||||
#include <QProcess>
|
||||
#include <QWidget>
|
||||
|
||||
class QPushButton;
|
||||
class QTextBrowser;
|
||||
|
||||
class MainWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("Author", "Alexander Popov")
|
||||
Q_CLASSINFO("Status", "Active")
|
||||
|
||||
private slots:
|
||||
void onButtonReleased();
|
||||
void onCaptureProcessOutput();
|
||||
|
||||
private:
|
||||
QPushButton *button;
|
||||
QTextBrowser *textBrowser;
|
||||
QProcess process;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_HPP
|
18
projects/Qt/example/src/main.cpp
Normal file
18
projects/Qt/example/src/main.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// qputenv("QT_STYLE_OVERRIDE", "adwaita-dark");
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
// qDebug() << "Hello World";
|
||||
|
||||
return app.exec();
|
||||
}
|
47
projects/Qt/example/src/mainwindow.cpp
Normal file
47
projects/Qt/example/src/mainwindow.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "mainwindow.hpp"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
|
||||
setWindowTitle(tr("ololo"));
|
||||
setGeometry(100, 100, 300, 200);
|
||||
|
||||
// widgets
|
||||
button = new QPushButton(tr("Push Me!"));
|
||||
textBrowser = new QTextBrowser();
|
||||
|
||||
// layout
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->addWidget(button, 0, 0);
|
||||
mainLayout->addWidget(textBrowser, 1, 0);
|
||||
setLayout(mainLayout);
|
||||
|
||||
// signals
|
||||
connect(button, SIGNAL(released()), this, SLOT(onButtonReleased()));
|
||||
connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(onCaptureProcessOutput()));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete button;
|
||||
delete textBrowser;
|
||||
}
|
||||
|
||||
void MainWindow::onButtonReleased() {
|
||||
textBrowser->clear();
|
||||
textBrowser->append(tr("Running command:\n"));
|
||||
|
||||
process.setCurrentWriteChannel(QProcess::StandardOutput);
|
||||
|
||||
process.start("ls", QStringList() << "-lh" << qgetenv("HOME"));
|
||||
// if (!process.waitForStarted() || !process.waitForFinished()) {
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
void MainWindow::onCaptureProcessOutput() {
|
||||
QProcess *proc = qobject_cast<QProcess *>(sender());
|
||||
|
||||
if (proc) {
|
||||
textBrowser->append(proc->readAllStandardOutput());
|
||||
}
|
||||
}
|
21
projects/Qt/example/xmake.lua
Normal file
21
projects/Qt/example/xmake.lua
Normal file
@ -0,0 +1,21 @@
|
||||
set_project("example")
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
if is_mode("debug") then
|
||||
set_symbols("debug")
|
||||
set_optimize("none")
|
||||
end
|
||||
|
||||
add_includedirs(
|
||||
"include" -- APPLICATION
|
||||
)
|
||||
add_linkdirs(
|
||||
)
|
||||
|
||||
target("example")
|
||||
-- set_kind("binary")
|
||||
add_rules("qt.widgetapp")
|
||||
add_headerfiles("include/*.hpp")
|
||||
add_files("src/*.cpp")
|
||||
-- add files with Q_OBJECT meta (only for qt.moc)
|
||||
add_files("include/*.hpp")
|
Loading…
Reference in New Issue
Block a user