diff --git a/Battery/batterywidget.cpp b/Battery/batterywidget.cpp index 52305e9..843b541 100644 --- a/Battery/batterywidget.cpp +++ b/Battery/batterywidget.cpp @@ -1,13 +1,16 @@ #include "batterywidget.h" -#include -#include -#include -#include -#include +#include -struct BatteryWidget::BatteryWidgetPrivate +class BatteryWidget::BatteryWidgetPrivate { +public: + BatteryWidgetPrivate(BatteryWidget *q) + : q_ptr(q) + {} + + BatteryWidget *q_ptr; + QColor borderColor = QColor(80, 80, 80); QColor powerColor = QColor(65, 205, 82); QColor alarmColor = QColor(250, 118, 113); @@ -18,7 +21,7 @@ struct BatteryWidget::BatteryWidgetPrivate BatteryWidget::BatteryWidget(QWidget *parent) : QWidget(parent) - , d_ptr(new BatteryWidgetPrivate) + , d_ptr(new BatteryWidgetPrivate(this)) { d_ptr->animation = new QPropertyAnimation(this, "value", this); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -73,14 +76,15 @@ auto BatteryWidget::minimumSizeHint() const -> QSize void BatteryWidget::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); + QPainter painter(this); painter.setPen(Qt::NoPen); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); - double linew = 2 * painter.pen().widthF() / painter.transform().m11(); + auto linew = 2 * painter.pen().widthF() / painter.transform().m11(); qreal headWidth = width() / 11; qreal batteryWidth = width() - headWidth; - QRectF batteryRect = QRectF(QPointF(5, 5), QPointF(batteryWidth, height() - 5)); + auto batteryRect = QRectF(QPointF(5, 5), QPointF(batteryWidth, height() - 5)); // 边框 drawBorder(&painter, batteryRect, linew); @@ -127,24 +131,24 @@ void BatteryWidget::setValue(int value) update(); } -void BatteryWidget::drawBorder(QPainter *painter, const QRectF &batteryRect, const double linew) +void BatteryWidget::drawBorder(QPainter *painter, const QRectF &batteryRect, const qreal linew) { painter->setPen(QPen(d_ptr->borderColor, linew)); painter->setBrush(Qt::NoBrush); - double borderRadius = batteryRect.height() / 30; + qreal borderRadius = batteryRect.height() / 30; painter->drawRoundedRect(batteryRect, borderRadius, borderRadius); } -void BatteryWidget::drawPower(QPainter *painter, const QRectF &batteryRect, const double linew) +void BatteryWidget::drawPower(QPainter *painter, const QRectF &batteryRect, const qreal linew) { - QColor powerColoer = d_ptr->value > d_ptr->alarmValue ? d_ptr->powerColor : d_ptr->alarmColor; - double margin = qMin(width(), height()) / 50.0; + auto powerColoer = d_ptr->value > d_ptr->alarmValue ? d_ptr->powerColor : d_ptr->alarmColor; + qreal margin = qMin(width(), height()) / 50.0; margin = qMax(margin, linew); qreal unit = (batteryRect.width() - (margin * 2)) / 100; QPointF topLeft(batteryRect.topLeft().x() + margin, batteryRect.topLeft().y() + margin); QPointF bottomRight(d_ptr->value * unit + margin + 5, batteryRect.bottomRight().y() - margin); QRectF rect(topLeft, bottomRight); - double bgRadius = rect.height() / 30; + qreal bgRadius = rect.height() / 30; painter->setPen(Qt::NoPen); painter->setBrush(powerColoer); painter->drawRoundedRect(rect, bgRadius, bgRadius); @@ -152,8 +156,8 @@ void BatteryWidget::drawPower(QPainter *painter, const QRectF &batteryRect, cons void BatteryWidget::drawValue(QPainter *painter, const QRectF &batteryRect) { - QColor fontColoer = d_ptr->value > d_ptr->alarmValue ? QColor(64, 65, 66) : d_ptr->alarmColor; - QString text = QString("%1%").arg(d_ptr->value); + auto fontColoer = d_ptr->value > d_ptr->alarmValue ? QColor(64, 65, 66) : d_ptr->alarmColor; + auto text = QString("%1%").arg(d_ptr->value); QFont font("Microsoft YaHei", batteryRect.width() / 5); font.setLetterSpacing(QFont::AbsoluteSpacing, batteryRect.width() / 25); painter->setFont(font); @@ -167,7 +171,7 @@ void BatteryWidget::drawHeader(QPainter *painter, const QRectF &batteryRect) QPointF headRectTopLeft(batteryRect.topRight().x(), height() / 3); QPointF headRectBottomRight(width(), height() - height() / 3); QRectF headRect(headRectTopLeft, headRectBottomRight); - double headRadius = headRect.height() / 30; + qreal headRadius = headRect.height() / 30; painter->setPen(Qt::NoPen); painter->setBrush(d_ptr->borderColor); painter->drawRoundedRect(headRect, headRadius, headRadius); diff --git a/Battery/batterywidget.h b/Battery/batterywidget.h index 942cd5c..5932fc3 100644 --- a/Battery/batterywidget.h +++ b/Battery/batterywidget.h @@ -14,20 +14,20 @@ class BatteryWidget : public QWidget explicit BatteryWidget(QWidget *parent = nullptr); ~BatteryWidget() override; - [[nodiscard]] [[nodiscard]] auto sizeHint() const -> QSize override; - [[nodiscard]] [[nodiscard]] auto minimumSizeHint() const -> QSize override; + [[nodiscard]] auto sizeHint() const -> QSize override; + [[nodiscard]] auto minimumSizeHint() const -> QSize override; void setBorderColor(const QColor &color); - [[nodiscard]] [[nodiscard]] auto borderColor() const -> QColor; + [[nodiscard]] auto borderColor() const -> QColor; void setPowerColor(const QColor &color); - [[nodiscard]] [[nodiscard]] auto powerColor() const -> QColor; + [[nodiscard]] auto powerColor() const -> QColor; void setAlarmColor(const QColor &color); - [[nodiscard]] [[nodiscard]] auto alarmColor() const -> QColor; + [[nodiscard]] auto alarmColor() const -> QColor; void setValue(int value); - [[nodiscard]] [[nodiscard]] auto value() const -> int; + [[nodiscard]] auto value() const -> int; signals: void valueChanged(int value); @@ -44,7 +44,7 @@ private slots: void drawValue(QPainter *painter, const QRectF &batteryRect); void drawHeader(QPainter *painter, const QRectF &batteryRect); - struct BatteryWidgetPrivate; + class BatteryWidgetPrivate; QScopedPointer d_ptr; }; diff --git a/Battery/mainwindow.cpp b/Battery/mainwindow.cpp index c14910d..0fb9351 100644 --- a/Battery/mainwindow.cpp +++ b/Battery/mainwindow.cpp @@ -6,13 +6,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - BatteryWidget *battery = new BatteryWidget(this); - QSlider *slider = new QSlider(this); + auto *battery = new BatteryWidget(this); + auto *slider = new QSlider(this); slider->setRange(0, 100); connect(slider, &QSlider::valueChanged, battery, &BatteryWidget::valueChanged); - QWidget *widget = new QWidget(this); - QHBoxLayout *layout = new QHBoxLayout(widget); + auto *widget = new QWidget(this); + auto *layout = new QHBoxLayout(widget); layout->addWidget(battery); layout->addWidget(slider); setCentralWidget(widget); diff --git a/BatteryQuick/Battery.qml b/BatteryQuick/Battery.qml new file mode 100644 index 0000000..c3dc2c8 --- /dev/null +++ b/BatteryQuick/Battery.qml @@ -0,0 +1,53 @@ +import QtQuick + +Rectangle { + id: root + + width: 200 + height: 100 + + property color borderColor: "#505008" + property color powerColor: "#41cd52" + property color alarmColor: "#fa7671" + property int alarmValue: 20 + property int value: 0 + + Rectangle { + id: batteryRect + + x: 10 + y: 10 + width: root.width - x * 3 + height: root.height - y * 2 + border.color: root.borderColor + border.width: 2 + radius: 5 + + Rectangle { + x: batteryRect.border.width * 2 + y: batteryRect.border.width * 2 + width: (batteryRect.width - x * 2) * (value / 100) + height: batteryRect.height - y * 2 + color: value > root.alarmValue ? root.powerColor : root.alarmColor + radius: batteryRect.radius + } + + Text { + text: value.toString() + "%" + font.pointSize: { + var width = batteryRect.width / 5 + return width > 0 ? width : 14 + } + color: value > root.alarmValue ? "black" : root.alarmColor + anchors.centerIn: batteryRect + } + } + + Rectangle { + width: 10 + height: 20 + color: root.borderColor + x: batteryRect.x + batteryRect.width + y: (root.height - height) / 2 + } +} diff --git a/BatteryQuick/BatteryQuick.pro b/BatteryQuick/BatteryQuick.pro new file mode 100644 index 0000000..01e0e73 --- /dev/null +++ b/BatteryQuick/BatteryQuick.pro @@ -0,0 +1,22 @@ +QT += quick + +SOURCES += \ + main.cc + +resources.files = Main.qml +resources.prefix = /$${TARGET} +RESOURCES += resources + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +resources.files += \ + Battery.qml diff --git a/BatteryQuick/CMakeLists.txt b/BatteryQuick/CMakeLists.txt new file mode 100644 index 0000000..25de76f --- /dev/null +++ b/BatteryQuick/CMakeLists.txt @@ -0,0 +1,25 @@ +qt_add_executable(BatteryQuick main.cc) + +qt_add_qml_module( + BatteryQuick + URI + BatteryResources + VERSION + 1.0 + QML_FILES + Main.qml + Battery.qml) + +# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. If +# you are developing for iOS or macOS you should consider setting an explicit, +# fixed bundle identifier manually though. +set_target_properties( + BatteryQuick + PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.BatteryQuick + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE) + +target_link_libraries(BatteryQuick PRIVATE Qt6::Quick) diff --git a/BatteryQuick/Main.qml b/BatteryQuick/Main.qml new file mode 100644 index 0000000..302867e --- /dev/null +++ b/BatteryQuick/Main.qml @@ -0,0 +1,71 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import QtQuick.Controls.Fusion + +Window { + id: root + + width: 300 + height: 160 + visible: true + title: qsTr("Battery") + + RowLayout { + spacing: 10 + anchors.fill: parent + + Battery { + id: battery + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.margins: 10 + value: 20 + } + + Slider { + id: control + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.margins: 10 + orientation: Qt.Vertical + focus: false + from: 0 + to: 100 + value: battery.value + + onValueChanged: { + // console.log("value: " + value) + battery.value = value + } + + background: Rectangle { + x: control.leftPadding + control.availableWidth / 2 - width / 2 + y: control.topPadding + width: 4 + height: control.availableHeight + radius: 2 + color: "#21be2b" + + Rectangle { + width: parent.width + height: control.visualPosition * parent.height + color: "#bdbebf" + radius: 2 + } + } + + handle: Rectangle { + x: control.leftPadding + control.availableWidth / 2 - width / 2 + y: control.topPadding + control.visualPosition * (control.availableHeight - height) + implicitWidth: 26 + implicitHeight: 26 + radius: 13 + color: control.pressed ? "#f0f0f0" : "#f6f6f6" + border.color: "#bdbebf" + } + } + } +} diff --git a/BatteryQuick/main.cc b/BatteryQuick/main.cc new file mode 100644 index 0000000..7e93ef0 --- /dev/null +++ b/BatteryQuick/main.cc @@ -0,0 +1,23 @@ +#include +#include + +auto main(int argc, char *argv[]) -> int +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + const QUrl url(u"qrc:/BatteryResources/Main.qml"_qs); + QObject::connect( + &engine, + &QQmlApplicationEngine::objectCreated, + &app, + [url](QObject *obj, const QUrl &objUrl) { + if ((obj == nullptr) && url == objUrl) { + QCoreApplication::exit(-1); + } + }, + Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/BubbleWindow/bubblewidget.cpp b/BubbleWindow/bubblewidget.cpp index 03fe409..68edd29 100644 --- a/BubbleWindow/bubblewidget.cpp +++ b/BubbleWindow/bubblewidget.cpp @@ -4,15 +4,14 @@ struct Triangle { - int width = 10; - int height = 10; + QSize size = QSize{10, 10}; BubbleWidget::Direction direct = BubbleWidget::Direction::Top; }; class BubbleWidget::BubbleWidgetPrivate { public: - BubbleWidgetPrivate(QWidget *parent) + explicit BubbleWidgetPrivate(QWidget *parent) : q_ptr(parent) { shadowEffect = new QGraphicsDropShadowEffect(q_ptr); @@ -36,20 +35,20 @@ class BubbleWidget::BubbleWidgetPrivate QPen pen = QColor(219, 186, 146); QBrush brush = QColor(255, 248, 240); - QString text = QLatin1String("Are you OK!"); + QString text = QLatin1String("Are you ok!"); }; BubbleWidget::BubbleWidget(QWidget *parent) : QWidget(parent) , d_ptr(new BubbleWidgetPrivate(this)) { - setWindowFlags(Qt::FramelessWindowHint | Qt::Popup | Qt::NoDropShadowWindowHint); + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Popup | Qt::NoDropShadowWindowHint); setAttribute(Qt::WA_TranslucentBackground); setupUI(); resize(200, 100); } -BubbleWidget::~BubbleWidget() {} +BubbleWidget::~BubbleWidget() = default; void BubbleWidget::setPen(const QPen &pen) { @@ -57,7 +56,7 @@ void BubbleWidget::setPen(const QPen &pen) update(); } -QPen BubbleWidget::pen() const +auto BubbleWidget::pen() const -> QPen { return d_ptr->pen; } @@ -68,7 +67,7 @@ void BubbleWidget::setBrush(const QBrush &brush) update(); } -QBrush BubbleWidget::brush() const +auto BubbleWidget::brush() const -> QBrush { return d_ptr->brush; } @@ -79,7 +78,7 @@ void BubbleWidget::setShadowWidth(qint64 width) update(); } -qint64 BubbleWidget::shadowWidth() +auto BubbleWidget::shadowWidth() -> qint64 { return d_ptr->shadowWidth; } @@ -90,7 +89,7 @@ void BubbleWidget::setBorderRadius(qint64 radius) update(); } -qint64 BubbleWidget::borderRadius() +auto BubbleWidget::borderRadius() -> qint64 { return d_ptr->borderRadius; } @@ -101,25 +100,29 @@ void BubbleWidget::setText(const QString &text) update(); } -QString BubbleWidget::text() const +auto BubbleWidget::text() const -> QString { return d_ptr->text; } -void BubbleWidget::setTriangleInfo(int width, int height) +void BubbleWidget::setTriangleSize(const QSize &size) { - d_ptr->triangle.width = width; - d_ptr->triangle.height = height; + d_ptr->triangle.size = size; update(); } +auto BubbleWidget::triangleSize() const -> QSize +{ + return d_ptr->triangle.size; +} + void BubbleWidget::setDerection(BubbleWidget::Direction dir) { d_ptr->triangle.direct = dir; update(); } -BubbleWidget::Direction BubbleWidget::direction() +auto BubbleWidget::direction() -> BubbleWidget::Direction { return d_ptr->triangle.direct; } @@ -132,7 +135,7 @@ void BubbleWidget::exec() loop.exec(); } -void BubbleWidget::paintEvent(QPaintEvent *) +void BubbleWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); @@ -146,53 +149,57 @@ void BubbleWidget::paintEvent(QPaintEvent *) switch (d_ptr->triangle.direct) { case Top: trianglePolygon << QPoint(width() / 2, d_ptr->shadowWidth); - trianglePolygon << QPoint(width() / 2 + d_ptr->triangle.width / 2, - d_ptr->triangle.height + d_ptr->shadowWidth); - trianglePolygon << QPoint(width() / 2 - d_ptr->triangle.width / 2, - d_ptr->triangle.height + d_ptr->shadowWidth); + trianglePolygon << QPoint(width() / 2 + d_ptr->triangle.size.width() / 2, + d_ptr->triangle.size.height() + d_ptr->shadowWidth); + trianglePolygon << QPoint(width() / 2 - d_ptr->triangle.size.width() / 2, + d_ptr->triangle.size.height() + d_ptr->shadowWidth); rect = QRect(d_ptr->shadowWidth, - d_ptr->triangle.height + d_ptr->shadowWidth, + d_ptr->triangle.size.height() + d_ptr->shadowWidth, width() - d_ptr->shadowWidth * 2, - height() - d_ptr->shadowWidth * 2 - d_ptr->triangle.height); + height() - d_ptr->shadowWidth * 2 - d_ptr->triangle.size.height()); drawPath.addRoundedRect(rect, d_ptr->borderRadius, d_ptr->borderRadius); break; case Left: trianglePolygon << QPoint(d_ptr->shadowWidth, - d_ptr->triangle.height + d_ptr->shadowWidth + d_ptr->shadowWidth); - trianglePolygon << QPoint(d_ptr->shadowWidth + d_ptr->triangle.width, + d_ptr->triangle.size.height() + d_ptr->shadowWidth + + d_ptr->shadowWidth); + trianglePolygon << QPoint(d_ptr->shadowWidth + d_ptr->triangle.size.width(), d_ptr->shadowWidth + d_ptr->shadowWidth); - trianglePolygon << QPoint(d_ptr->shadowWidth + d_ptr->triangle.width, - d_ptr->triangle.height + d_ptr->shadowWidth + d_ptr->shadowWidth); - rect = QRect(d_ptr->shadowWidth + d_ptr->triangle.width, + trianglePolygon << QPoint(d_ptr->shadowWidth + d_ptr->triangle.size.width(), + d_ptr->triangle.size.height() + d_ptr->shadowWidth + + d_ptr->shadowWidth); + rect = QRect(d_ptr->shadowWidth + d_ptr->triangle.size.width(), d_ptr->shadowWidth, - width() - d_ptr->shadowWidth * 2 - d_ptr->triangle.width, + width() - d_ptr->shadowWidth * 2 - d_ptr->triangle.size.width(), height() - d_ptr->shadowWidth * 2); drawPath.addRoundedRect(rect, d_ptr->borderRadius, d_ptr->borderRadius); break; case Right: - trianglePolygon << QPoint(width() - d_ptr->shadowWidth - d_ptr->triangle.width, + trianglePolygon << QPoint(width() - d_ptr->shadowWidth - d_ptr->triangle.size.width(), d_ptr->shadowWidth + d_ptr->shadowWidth); - trianglePolygon << QPoint(width() - d_ptr->shadowWidth - d_ptr->triangle.width, - d_ptr->triangle.height + d_ptr->shadowWidth + d_ptr->shadowWidth); + trianglePolygon << QPoint(width() - d_ptr->shadowWidth - d_ptr->triangle.size.width(), + d_ptr->triangle.size.height() + d_ptr->shadowWidth + + d_ptr->shadowWidth); trianglePolygon << QPoint(width() - d_ptr->shadowWidth, - d_ptr->triangle.height + d_ptr->shadowWidth + d_ptr->shadowWidth); + d_ptr->triangle.size.height() + d_ptr->shadowWidth + + d_ptr->shadowWidth); rect = QRect(d_ptr->shadowWidth, d_ptr->shadowWidth, - width() - d_ptr->shadowWidth * 2 - d_ptr->triangle.width, + width() - d_ptr->shadowWidth * 2 - d_ptr->triangle.size.width(), height() - d_ptr->shadowWidth * 2); drawPath.addRoundedRect(rect, d_ptr->borderRadius, d_ptr->borderRadius); break; case Bottom: trianglePolygon << QPoint(width() / 2, height() - d_ptr->shadowWidth); - trianglePolygon << QPoint(width() / 2 + d_ptr->triangle.width / 2, - height() - d_ptr->shadowWidth - d_ptr->triangle.height); - trianglePolygon << QPoint(width() / 2 - d_ptr->triangle.width / 2, - height() - d_ptr->shadowWidth - d_ptr->triangle.height); + trianglePolygon << QPoint(width() / 2 + d_ptr->triangle.size.width() / 2, + height() - d_ptr->shadowWidth - d_ptr->triangle.size.height()); + trianglePolygon << QPoint(width() / 2 - d_ptr->triangle.size.width() / 2, + height() - d_ptr->shadowWidth - d_ptr->triangle.size.height()); rect = QRect(d_ptr->shadowWidth, d_ptr->shadowWidth, width() - d_ptr->shadowWidth * 2, - height() - d_ptr->shadowWidth * 2 - d_ptr->triangle.height); + height() - d_ptr->shadowWidth * 2 - d_ptr->triangle.size.height()); drawPath.addRoundedRect(rect, d_ptr->borderRadius, d_ptr->borderRadius); break; } @@ -214,9 +221,9 @@ void BubbleWidget::closeEvent(QCloseEvent *event) void BubbleWidget::setupUI() { setGraphicsEffect(d_ptr->shadowEffect); - QHBoxLayout *layout = new QHBoxLayout(this); + auto *layout = new QHBoxLayout(this); layout->setContentsMargins(d_ptr->shadowWidth + 10, - d_ptr->shadowWidth + d_ptr->triangle.height + 20, + d_ptr->shadowWidth + d_ptr->triangle.size.height() + 20, d_ptr->shadowWidth + 10, d_ptr->shadowWidth + 10); layout->addWidget(d_ptr->centralWidget); diff --git a/BubbleWindow/bubblewidget.h b/BubbleWindow/bubblewidget.h index 32431d6..851b62a 100644 --- a/BubbleWindow/bubblewidget.h +++ b/BubbleWindow/bubblewidget.h @@ -28,7 +28,8 @@ class BubbleWidget : public QWidget [[nodiscard]] auto text() const -> QString; // 设置小三角宽和高; - void setTriangleInfo(int width, int height); + void setTriangleSize(const QSize &size); + [[nodiscard]] auto triangleSize() const -> QSize; void setDerection(Direction); auto direction() -> Direction; @@ -39,7 +40,7 @@ class BubbleWidget : public QWidget void aboutToClose(); protected: - void paintEvent(QPaintEvent *) override; + void paintEvent(QPaintEvent *event) override; void closeEvent(QCloseEvent *event) override; private: diff --git a/BubbleWindow/mainwindow.cpp b/BubbleWindow/mainwindow.cpp index 32fb0cc..3d384b1 100644 --- a/BubbleWindow/mainwindow.cpp +++ b/BubbleWindow/mainwindow.cpp @@ -2,8 +2,8 @@ #include "bubblewidget.h" -#include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -14,24 +14,24 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::setupUI() { - BubbleWidget *top = new BubbleWidget(this); - top->setTriangleInfo(20, 20); + auto *top = new BubbleWidget(this); + top->setTriangleSize({20, 20}); top->setDerection(BubbleWidget::Top); - BubbleWidget *left = new BubbleWidget(this); - left->setTriangleInfo(20, 20); + auto *left = new BubbleWidget(this); + left->setTriangleSize({20, 20}); left->setDerection(BubbleWidget::Left); - BubbleWidget *right = new BubbleWidget(this); - right->setTriangleInfo(20, 20); + auto *right = new BubbleWidget(this); + right->setTriangleSize({20, 20}); right->setDerection(BubbleWidget::Right); - BubbleWidget *bottom = new BubbleWidget(this); - bottom->setTriangleInfo(20, 20); + auto *bottom = new BubbleWidget(this); + bottom->setTriangleSize({20, 20}); bottom->setDerection(BubbleWidget::Bottom); - QWidget *widget = new QWidget(this); - QVBoxLayout *layout = new QVBoxLayout(widget); + auto *widget = new QWidget(this); + auto *layout = new QVBoxLayout(widget); layout->addWidget(top); layout->addWidget(left); layout->addWidget(right); @@ -39,4 +39,3 @@ void MainWindow::setupUI() setCentralWidget(widget); } - diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d99efc..0c597c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,18 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 REQUIRED COMPONENTS Core Widgets Charts Network Concurrent Sql) +find_package( + Qt6 REQUIRED + COMPONENTS Core + Widgets + Charts + Network + Concurrent + Sql + Quick) add_subdirectory(Battery) +add_subdirectory(BatteryQuick) add_subdirectory(Bootstrap) add_subdirectory(BubbleWindow) add_subdirectory(Chart) diff --git a/Qt-Examples.pro b/Qt-Examples.pro index 8a9e20e..850e1eb 100644 --- a/Qt-Examples.pro +++ b/Qt-Examples.pro @@ -3,6 +3,7 @@ CONFIG += ordered SUBDIRS += \ Battery \ + BatteryQuick \ Bootstrap \ BubbleWindow \ Chart \ diff --git a/README.md b/README.md index 40c1bfc..9e9a758 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## [QT实用小技巧(想到就更新) | 自由意志 (realchuan.github.io)](https://realchuan.github.io/2021/10/12/QT%E5%AE%9E%E7%94%A8%E5%B0%8F%E6%8A%80%E5%B7%A7%EF%BC%88%E6%83%B3%E5%88%B0%E5%B0%B1%E6%9B%B4%E6%96%B0%EF%BC%89/) -## [Battery](/Battery/)——电池 +## [Battery](/Battery/)——电池控件 @@ -14,6 +14,8 @@
+## [BatteryQuick](/BatteryQuick/)--电池控件(`QtQuick`) + ## [Bootstarp](/Bootstarp/)--程序开机自启动设置和检测 1. Windows下读写注册表实现开机自启动,有两个位置可以写入;