添加动画效果
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#include <loginWindow.h>
|
||||
@@ -0,0 +1,85 @@
|
||||
#include <QApplication>
|
||||
#include <QDialog>
|
||||
#include <QVBoxLayout>
|
||||
#include <QRegion>
|
||||
#include <qpainter.h>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <opencv.hpp>
|
||||
#include <uiModule/components/fancyButton.h>
|
||||
#include <globalStruct.h>
|
||||
#include <qobject.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
class loginWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QVBoxLayout* layout;
|
||||
QLineEdit passwordEdit;
|
||||
fancyButtonText* button, * exitBtn;
|
||||
QLabel* label;
|
||||
QComboBox* comboBox;
|
||||
QLabel tipLabel;
|
||||
loginWindow()
|
||||
{
|
||||
this->setObjectName("LoginWindow");
|
||||
this->setStyleSheet(QString("QWidget#LoginWindow {background-color: rgb(%1)}").arg(sColor_blue));
|
||||
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::WindowText, Qt::white);
|
||||
|
||||
layout= new QVBoxLayout(this);
|
||||
button = new fancyButtonText(100,40,"确定","");
|
||||
|
||||
label=new QLabel("欢迎!");
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
label->setFont(QFont("Microsoft YaHei", 30, QFont::Bold));
|
||||
label->setPalette(palette);
|
||||
|
||||
comboBox= new QComboBox;
|
||||
comboBox->addItems({ u8"工程师",u8"售后",u8"调试" });
|
||||
comboBox->setFont(QFont("Microsoft YaHei", 14));
|
||||
comboBox->setStyleSheet("QComboBox { padding-left: 4px; padding-right: 4px; }"
|
||||
"QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: right; }"
|
||||
"QComboBox::down-arrow { image: url(./arrow.png); }"
|
||||
"QComboBox::down-arrow:on { top: 1px; left: 1px; }"
|
||||
"QComboBox QAbstractItemView { padding: 2px; }"
|
||||
"QComboBox::item { padding: 2px 4px; },");
|
||||
comboBox->setFixedHeight(40);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(comboBox);
|
||||
|
||||
passwordEdit.setFixedHeight(40);
|
||||
passwordEdit.setFont(QFont("Microsoft YaHei", 12, QFont::Bold));
|
||||
layout->addWidget(&passwordEdit);
|
||||
|
||||
exitBtn = new fancyButtonText(100, 40, u8"退出", "");
|
||||
QObject::connect(exitBtn, &QPushButton::clicked, [=]() {
|
||||
exit(0);
|
||||
});
|
||||
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->addWidget(button);
|
||||
QHBoxLayout* extButtonLayout = new QHBoxLayout();
|
||||
extButtonLayout->addWidget(exitBtn);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addLayout(extButtonLayout);
|
||||
layout->setAlignment(Qt::AlignCenter);
|
||||
|
||||
|
||||
QObject::connect(button, &QPushButton::clicked, this, &loginWindow::comparePassword);
|
||||
//this->show();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void comparePassword()
|
||||
{
|
||||
emit login(true);
|
||||
}
|
||||
signals:
|
||||
void login(bool);
|
||||
};
|
||||
#pragma once
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <qlineedit.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <uiModule/uiModule_LoginWindow.h>
|
||||
int main ( int argc, char *argv[] )
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
@@ -26,27 +26,41 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
this->setMaximumSize(9999, 9999);
|
||||
this->setObjectName("MainWidget");
|
||||
this->setStyleSheet(QString("QWidget#MainWidget {background-color: rgb(%1)}").arg(sColor_blue));
|
||||
this->setCentralWidget(&stackedWidgets);
|
||||
|
||||
//加载界面初始化
|
||||
|
||||
|
||||
//登录界面
|
||||
stackedWidgets.addWidget(&_loginWindow);
|
||||
connect(&_loginWindow, &loginWindow::login, this, &MainWindow::login);
|
||||
|
||||
//第一层 只有顶部菜单栏和第二层layout
|
||||
mainWdiget = new QWidget(this);
|
||||
this, setCentralWidget(mainWdiget);
|
||||
mainLayout = new QVBoxLayout(mainWdiget);
|
||||
mainWidget = new QWidget();
|
||||
stackedWidgets.addWidget(mainWidget);
|
||||
mainLayout = new QVBoxLayout(mainWidget);
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
topBarInit();
|
||||
|
||||
//第二层 只有左侧菜单栏和主界面
|
||||
mainWdiget2 = new QWidget(this);
|
||||
mainLayout2 = new QHBoxLayout(mainWdiget2);
|
||||
mainWidget2 = new QWidget();
|
||||
mainLayout2 = new QHBoxLayout(mainWidget2);
|
||||
mainLayout2->setAlignment(Qt::AlignLeft);
|
||||
mainLayout2->setContentsMargins(0, 0, 0, 0);
|
||||
mainLayout->addWidget(mainWdiget2);
|
||||
mainLayout->addWidget(mainWidget2);
|
||||
|
||||
mainWidgets = new QStackedWidget();
|
||||
leftBarInit();
|
||||
mainLayout2->addWidget(mainWidgets);
|
||||
//显示界面初始化
|
||||
|
||||
//_displayWidget->windowChanged();
|
||||
mainLayout2->addWidget(&pageWidgets);
|
||||
|
||||
//动画
|
||||
blurEffect = new QGraphicsBlurEffect();
|
||||
//毛玻璃效果
|
||||
this->setGraphicsEffect(blurEffect);
|
||||
blurEffectAnimation = new QPropertyAnimation(blurEffect, "blurRadius");
|
||||
blurEffectAnimation->setDuration(50);
|
||||
blurEffectAnimation->setEndValue(0);
|
||||
blurEffectAnimation->start();
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -180,7 +194,7 @@ void MainWindow::leftBarInit()
|
||||
QIcon(":/topBar/icon/home.png"),
|
||||
u8"主界面");
|
||||
_displayWidget = new displayWidget();
|
||||
mainWidgets->addWidget(_displayWidget);
|
||||
pageWidgets.addWidget(_displayWidget);
|
||||
pageBtns.push_back(toMainBtn);
|
||||
|
||||
//配置页面
|
||||
@@ -190,7 +204,7 @@ void MainWindow::leftBarInit()
|
||||
QIcon(":/topBar/icon/setting.png"),
|
||||
u8"配置设置");
|
||||
_configSettingWidget = new configSettingWidget();
|
||||
mainWidgets->addWidget(_configSettingWidget);
|
||||
pageWidgets.addWidget(_configSettingWidget);
|
||||
pageBtns.push_back(configBtn);
|
||||
|
||||
//日志页面
|
||||
@@ -200,7 +214,7 @@ void MainWindow::leftBarInit()
|
||||
QIcon(":/topBar/icon/config.png"),
|
||||
u8"日志");
|
||||
_logWidget = new logWidget();
|
||||
mainWidgets->addWidget(_logWidget);
|
||||
pageWidgets.addWidget(_logWidget);
|
||||
pageBtns.push_back(logBtn);
|
||||
|
||||
for (int index = 0; index < pageBtns.size(); index++)
|
||||
@@ -214,7 +228,7 @@ void MainWindow::leftBarInit()
|
||||
pageBtns[index2]->toDefault();
|
||||
}
|
||||
pageBtns[index]->pressed();
|
||||
mainWidgets->setCurrentIndex(index);
|
||||
pageWidgets.setCurrentIndex(index);
|
||||
qInfo() << "switch Page to Index:" << index;
|
||||
qDebug() << "switch Page to Index:" << index;
|
||||
});
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <pages/configSettingWidget.h>
|
||||
#include <QStackedWidget>
|
||||
#include <pages/logPageWidget.h>
|
||||
#include <LoginWindow.h>
|
||||
#include <QPropertyAnimation>
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
enum DRAG_ABSOLUTE_POSITION
|
||||
@@ -42,12 +44,20 @@ public:
|
||||
~MainWindow();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
//主要控件
|
||||
std::vector<toolBarButton*>pageBtns;
|
||||
QStackedWidget stackedWidgets;//一共三层,加载界面,登录界面,主要界面
|
||||
QStackedWidget pageWidgets;//主要界面中的页面
|
||||
loginWindow _loginWindow;
|
||||
|
||||
//动画效果
|
||||
QGraphicsBlurEffect* blurEffect;
|
||||
QPropertyAnimation* blurEffectAnimation;
|
||||
|
||||
QVBoxLayout* mainLayout;
|
||||
QHBoxLayout* mainLayout2;
|
||||
QWidget* mainWdiget;
|
||||
QWidget* mainWdiget2;
|
||||
QWidget* mainWidget;
|
||||
QWidget* mainWidget2;
|
||||
|
||||
displayWidget* _displayWidget;
|
||||
configSettingWidget* _configSettingWidget;
|
||||
@@ -55,7 +65,7 @@ private:
|
||||
|
||||
QPushButton* maximizeRestoreButton;
|
||||
|
||||
QStackedWidget* mainWidgets;
|
||||
|
||||
bool isMoving = false;
|
||||
QPoint startPos;
|
||||
QRect startFrameGeometry;
|
||||
@@ -67,7 +77,6 @@ public slots:
|
||||
{
|
||||
showMinimized();
|
||||
}
|
||||
|
||||
void toggleMaximize()
|
||||
{
|
||||
if (isMaximized()) {
|
||||
@@ -80,6 +89,25 @@ public slots:
|
||||
}
|
||||
_displayWidget->windowChanged();
|
||||
}
|
||||
void switchstackedWidgets(int index)
|
||||
{
|
||||
stackedWidgets.setCurrentIndex(index);
|
||||
}
|
||||
void login(bool input)
|
||||
{
|
||||
if (input == true)
|
||||
{
|
||||
blurEffectAnimation->setStartValue(0);
|
||||
blurEffectAnimation->setEndValue(20);
|
||||
blurEffectAnimation->start();
|
||||
stackedWidgets.setCurrentIndex(1);
|
||||
blurEffectAnimation->setStartValue(20);
|
||||
blurEffectAnimation->setEndValue(0);
|
||||
blurEffectAnimation->start();
|
||||
|
||||
}
|
||||
else if(input == false)stackedWidgets.setCurrentIndex(0);
|
||||
}
|
||||
signals:
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
#include <QApplication>
|
||||
#include <QDialog>
|
||||
#include <QVBoxLayout>
|
||||
#include <QRegion>
|
||||
#include <qpainter.h>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <opencv.hpp>
|
||||
#include <uiModule/components/fancyButton.h>
|
||||
QPixmap matToPixmap(const cv::Mat& mat) {
|
||||
// 将OpenCV的Mat转换为Qt的QImage
|
||||
QImage img(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
|
||||
img = img.rgbSwapped(); // 颜色通道顺序转换(OpenCV使用BGR,而QImage使用RGB)
|
||||
|
||||
// 将QImage转换为QPixmap
|
||||
return QPixmap::fromImage(img);
|
||||
}
|
||||
|
||||
class loginDialog : public QDialog {
|
||||
public:
|
||||
QVBoxLayout* layout;
|
||||
QLineEdit* lineEdit;
|
||||
QPushButton* button;
|
||||
QLabel* label;
|
||||
QComboBox* comboBox;
|
||||
QPushButton* exitBtn;
|
||||
loginDialog(QWidget* parent = nullptr) : QDialog(parent) {
|
||||
this->setFixedSize(QSize(450, 300));
|
||||
this->setWindowFlags(Qt::FramelessWindowHint);
|
||||
this->setStyleSheet("QDialog {"
|
||||
" background-color: white;"
|
||||
" border: 2px solid orange;"
|
||||
" border-radius: 10px;"
|
||||
"}");
|
||||
layout= new QVBoxLayout(this);
|
||||
lineEdit =new QLineEdit (this);
|
||||
//button = new CustomButton("确定", this);
|
||||
// 设置QPushButton为全透明
|
||||
|
||||
|
||||
label=new QLabel("欢迎!");
|
||||
label->setAlignment(Qt::AlignHCenter);
|
||||
label->setFont(QFont("Microsoft YaHei", 18, QFont::Bold));
|
||||
|
||||
comboBox= new QComboBox;
|
||||
comboBox->addItems({ u8"工程师",u8"售后",u8"调试" });
|
||||
comboBox->setFont(QFont("Microsoft YaHei", 14));
|
||||
comboBox->setStyleSheet("QComboBox { padding-left: 4px; padding-right: 4px; }"
|
||||
"QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: right; }"
|
||||
"QComboBox::down-arrow { image: url(./arrow.png); }"
|
||||
"QComboBox::down-arrow:on { top: 1px; left: 1px; }"
|
||||
"QComboBox QAbstractItemView { padding: 2px; }"
|
||||
"QComboBox::item { padding: 2px 4px; },");
|
||||
comboBox->setFixedHeight(40);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(comboBox);
|
||||
lineEdit->setFixedHeight(40);
|
||||
lineEdit->setFont(QFont("Microsoft YaHei", 12, QFont::Bold));
|
||||
layout->addWidget(lineEdit);
|
||||
|
||||
exitBtn = new QPushButton(u8"退出");
|
||||
exitBtn->setFixedWidth(30);
|
||||
exitBtn->setStyleSheet("QPushButton { background-color: transparent; border: none; }");
|
||||
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout();
|
||||
buttonLayout->addWidget(button);
|
||||
QHBoxLayout* extButtonLayout = new QHBoxLayout();
|
||||
extButtonLayout->addWidget(exitBtn);
|
||||
layout->addLayout(buttonLayout);
|
||||
layout->addLayout(extButtonLayout);
|
||||
layout->setAlignment(Qt::AlignCenter);
|
||||
QObject::connect(button, &QPushButton::clicked, this, &QDialog::accept);
|
||||
this->show();
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override {
|
||||
Q_UNUSED(event);
|
||||
|
||||
QPainterPath roundedPath;
|
||||
|
||||
// 构建一个圆角矩形的路径
|
||||
int radius = 10; // 圆角半径
|
||||
roundedPath.addRoundedRect(rect(), radius, radius);
|
||||
|
||||
// 设置裁剪区域
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setClipPath(roundedPath);
|
||||
|
||||
// 在窗口上绘制内容
|
||||
painter.fillRect(rect(), Qt::white); // 设置窗口背景色
|
||||
|
||||
int lineRadius=8;
|
||||
int borderWidth = 8; // 调整边框宽度
|
||||
QPen borderPen(QColor(235, 92, 32)); // 橙色
|
||||
borderPen.setWidth(borderWidth);
|
||||
painter.setPen(borderPen);
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRoundedRect(rect().adjusted(borderWidth / 2, borderWidth / 2, -borderWidth / 2, -borderWidth / 2), lineRadius, lineRadius);
|
||||
}
|
||||
};
|
||||
#pragma once
|
||||
Reference in New Issue
Block a user