diff --git a/projects/Qt/example/.clang-format b/projects/Qt/example/.clang-format new file mode 120000 index 0000000..ead1f91 --- /dev/null +++ b/projects/Qt/example/.clang-format @@ -0,0 +1 @@ +../../../code/C++/.clang-format \ No newline at end of file diff --git a/projects/Qt/example/.gitignore b/projects/Qt/example/.gitignore new file mode 100644 index 0000000..f8dc577 --- /dev/null +++ b/projects/Qt/example/.gitignore @@ -0,0 +1,11 @@ +# xmake +.xmake/ +build/ + +# qmake +.qmake.stash +*.o +moc_*.cpp +moc_*.j +moc_predefs.h +Makefile diff --git a/projects/Qt/example/README.md b/projects/Qt/example/README.md new file mode 100644 index 0000000..2513f88 --- /dev/null +++ b/projects/Qt/example/README.md @@ -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"). +``` diff --git a/projects/Qt/example/hello.pro b/projects/Qt/example/hello.pro new file mode 100644 index 0000000..496b1b4 --- /dev/null +++ b/projects/Qt/example/hello.pro @@ -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 diff --git a/projects/Qt/example/include/mainwindow.hpp b/projects/Qt/example/include/mainwindow.hpp new file mode 100644 index 0000000..e7244d9 --- /dev/null +++ b/projects/Qt/example/include/mainwindow.hpp @@ -0,0 +1,29 @@ +#ifndef MAINWINDOW_HPP +#define MAINWINDOW_HPP + +#include +#include + +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 diff --git a/projects/Qt/example/src/main.cpp b/projects/Qt/example/src/main.cpp new file mode 100644 index 0000000..b688659 --- /dev/null +++ b/projects/Qt/example/src/main.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +#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(); +} diff --git a/projects/Qt/example/src/mainwindow.cpp b/projects/Qt/example/src/mainwindow.cpp new file mode 100644 index 0000000..f88523c --- /dev/null +++ b/projects/Qt/example/src/mainwindow.cpp @@ -0,0 +1,47 @@ +#include + +#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(sender()); + + if (proc) { + textBrowser->append(proc->readAllStandardOutput()); + } +} diff --git a/projects/Qt/example/xmake.lua b/projects/Qt/example/xmake.lua new file mode 100644 index 0000000..3906ca8 --- /dev/null +++ b/projects/Qt/example/xmake.lua @@ -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")