Files
handleaiuinew/HanddleAI/HandleAiUi-new/uiModule/uiModule_LoginWindow.h
T
2024-05-18 23:53:26 +08:00

105 lines
3.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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