Commit b25211ae authored by ym0408's avatar ym0408

2

parent 914ec9fd
//#include "MultiFunctionDialog.h"
//#include "ui_MultiFunctionDialog.h"
//MultiFunctionDialog::MultiFunctionDialog(DialogType type,QWidget *parent) :
// QDialog(parent),m_dialogType(type),
// ui(new Ui::MultiFunctionDialog)
//{
// //ui->setupUi(this);
// setWindowFlags(Qt::FramelessWindowHint);
// // 弹窗基础样式
// setWindowTitle("选择设置");
// setFixedSize(1800, 800); // 统一弹窗大小(可根据类型微调)
// // 根据类型初始化对应的UI
// switch (m_dialogType) {
// case WorkStationType:
// setWindowTitle("请选择要设置的工位");
// initWorkStationUI();
// break;
// case DeviceType:
// setWindowTitle("请选择设备名称");
// initDeviceUI();
// break;
// case InspectionType:
// setWindowTitle("请选择抽检项类型");
// initInspectionUI();
// break;
// case TimeRangeType:
// setWindowTitle("请选择时间范围");
// setFixedSize(400, 320); // 时间弹窗稍大
// initTimeRangeUI();
// break;
// }
//}
//MultiFunctionDialog::~MultiFunctionDialog()
//{
// delete ui;
//}
//// -------------------------- 1. 初始化工位选择UI --------------------------
//void MultiFunctionDialog::initWorkStationUI() {
// // 标题
// QLabel *titleLabel = new QLabel("请选择要设置的工位", this);
// titleLabel->setAlignment(Qt::AlignCenter);
// // 工位列表
// m_listWidget = new QListWidget(this);
// QStringList stations = {"KOER", "KOEO", "PEPS", "KOGH", "KMOK"};
// m_listWidget->addItems(stations);
// m_listWidget->setSelectionMode(QListWidget::SingleSelection);
// m_listWidget->setCurrentRow(2); // 默认选中PEPS
// // 列表样式
// m_listWidget->setStyleSheet(R"(
// QListWidget::item { padding: 8px; text-align: center; }
// QListWidget::item:selected { background-color: #f0f0f0; color: #00bcd4; }
// )");
// // 按钮
// QPushButton *confirmBtn = new QPushButton("确认修改", this);
// QPushButton *cancelBtn = new QPushButton("取消修改", this);
// confirmBtn->setStyleSheet("background-color: #00bcd4; color: white; padding: 8px; border: none; border-radius: 4px;");
// cancelBtn->setStyleSheet("background-color: #e0e0e0; color: #333; padding: 8px; border: none; border-radius: 4px;");
// // 布局
// QVBoxLayout *mainLayout = new QVBoxLayout(this);
// QHBoxLayout *btnLayout = new QHBoxLayout;
// btnLayout->addWidget(confirmBtn);
// btnLayout->addWidget(cancelBtn);
// mainLayout->addWidget(titleLabel);
// mainLayout->addWidget(m_listWidget);
// mainLayout->addLayout(btnLayout);
// // 绑定按钮事件
// connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
// connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
//}
//// -------------------------- 2. 初始化设备选择UI --------------------------
//void MultiFunctionDialog::initDeviceUI() {
// QLabel *titleLabel = new QLabel("请选择设备名称", this);
// titleLabel->setAlignment(Qt::AlignCenter);
// m_listWidget = new QListWidget(this);
// QStringList devices = {"设备A", "设备B", "设备C", "设备D", "设备E"};
// m_listWidget->addItems(devices);
// m_listWidget->setSelectionMode(QListWidget::SingleSelection);
// m_listWidget->setCurrentRow(0);
// m_listWidget->setStyleSheet(R"(
// QListWidget::item { padding: 8px; text-align: center; }
// QListWidget::item:selected { background-color: #f0f0f0; color: #00bcd4; }
// )");
// QPushButton *confirmBtn = new QPushButton("确认", this);
// QPushButton *cancelBtn = new QPushButton("取消", this);
// confirmBtn->setStyleSheet("background-color: #00bcd4; color: white; padding: 8px; border: none; border-radius: 4px;");
// cancelBtn->setStyleSheet("background-color: #e0e0e0; color: #333; padding: 8px; border: none; border-radius: 4px;");
// QVBoxLayout *mainLayout = new QVBoxLayout(this);
// QHBoxLayout *btnLayout = new QHBoxLayout;
// btnLayout->addWidget(confirmBtn);
// btnLayout->addWidget(cancelBtn);
// mainLayout->addWidget(titleLabel);
// mainLayout->addWidget(m_listWidget);
// mainLayout->addLayout(btnLayout);
// connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
// connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
//}
//// -------------------------- 3. 初始化抽检项选择UI --------------------------
//void MultiFunctionDialog::initInspectionUI() {
// QLabel *titleLabel = new QLabel("请选择抽检项类型", this);
// titleLabel->setAlignment(Qt::AlignCenter);
// // 单选按钮组
// m_radioGroup = new QButtonGroup(this);
// QRadioButton *rbMust = new QRadioButton("必检", this);
// QRadioButton *rbSample = new QRadioButton("抽检", this);
// QRadioButton *rbBoth = new QRadioButton("必检&抽检", this);
// m_radioGroup->addButton(rbMust);
// m_radioGroup->addButton(rbSample);
// m_radioGroup->addButton(rbBoth);
// rbBoth->setChecked(true); // 默认选中
// // 单选按钮样式
// rbMust->setStyleSheet("margin: 8px; font-size: 14px;");
// rbSample->setStyleSheet("margin: 8px; font-size: 14px;");
// rbBoth->setStyleSheet("margin: 8px; font-size: 14px;");
// QPushButton *confirmBtn = new QPushButton("确认", this);
// QPushButton *cancelBtn = new QPushButton("取消", this);
// confirmBtn->setStyleSheet("background-color: #00bcd4; color: white; padding: 8px; border: none; border-radius: 4px;");
// cancelBtn->setStyleSheet("background-color: #e0e0e0; color: #333; padding: 8px; border: none; border-radius: 4px;");
// QVBoxLayout *mainLayout = new QVBoxLayout(this);
// QHBoxLayout *btnLayout = new QHBoxLayout;
// btnLayout->addWidget(confirmBtn);
// btnLayout->addWidget(cancelBtn);
// mainLayout->addWidget(titleLabel);
// mainLayout->addWidget(rbMust);
// mainLayout->addWidget(rbSample);
// mainLayout->addWidget(rbBoth);
// mainLayout->addLayout(btnLayout);
// connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
// connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
//}
//// -------------------------- 4. 初始化时间范围选择UI --------------------------
//void MultiFunctionDialog::initTimeRangeUI() {
// QLabel *titleLabel = new QLabel("请选择时间范围", this);
// titleLabel->setAlignment(Qt::AlignCenter);
// // 日历控件(辅助选择)
// QCalendarWidget *calendar = new QCalendarWidget(this);
// calendar->setSelectedDate(QDate::currentDate());
// calendar->setGridVisible(true);
// calendar->setMaximumHeight(180);
// // 日期编辑框
// QLabel *startLabel = new QLabel("开始日期:", this);
// QLabel *endLabel = new QLabel("结束日期:", this);
// m_startDateEdit = new QDateEdit(QDate::currentDate(), this);
// m_endDateEdit = new QDateEdit(QDate::currentDate().addDays(2), this);
// m_startDateEdit->setCalendarPopup(true);
// m_endDateEdit->setCalendarPopup(true);
// m_startDateEdit->setFixedWidth(120);
// m_endDateEdit->setFixedWidth(120);
// // 日期布局
// QHBoxLayout *dateLayout = new QHBoxLayout;
// dateLayout->addWidget(startLabel);
// dateLayout->addWidget(m_startDateEdit);
// dateLayout->addSpacing(20);
// dateLayout->addWidget(endLabel);
// dateLayout->addWidget(m_endDateEdit);
// QPushButton *confirmBtn = new QPushButton("确认", this);
// QPushButton *cancelBtn = new QPushButton("取消", this);
// confirmBtn->setStyleSheet("background-color: #00bcd4; color: white; padding: 8px; border: none; border-radius: 4px;");
// cancelBtn->setStyleSheet("background-color: #e0e0e0; color: #333; padding: 8px; border: none; border-radius: 4px;");
// QVBoxLayout *mainLayout = new QVBoxLayout(this);
// QHBoxLayout *btnLayout = new QHBoxLayout;
// btnLayout->addWidget(confirmBtn);
// btnLayout->addWidget(cancelBtn);
// mainLayout->addWidget(titleLabel);
// mainLayout->addWidget(calendar);
// mainLayout->addLayout(dateLayout);
// mainLayout->addLayout(btnLayout);
// connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
// connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
//}
//// -------------------------- 获取选择结果 --------------------------
//QString MultiFunctionDialog::getStringResult() const {
// switch (m_dialogType) {
// case WorkStationType:
// // 返回选中的工位
// if (m_listWidget->currentItem()) {
// return m_listWidget->currentItem()->text();
// }
// break;
// case DeviceType:
// // 返回选中的设备
// if (m_listWidget->currentItem()) {
// return m_listWidget->currentItem()->text();
// }
// break;
// case InspectionType:
// // 返回选中的抽检项
// if (m_radioGroup->checkedButton()) {
// return m_radioGroup->checkedButton()->text();
// }
// break;
// default:
// break;
// }
// return "";
//}
//QPair<QDate, QDate> MultiFunctionDialog::getTimeRangeResult() const {
// // 仅时间范围弹窗返回日期对
// if (m_dialogType == TimeRangeType) {
// return {m_startDateEdit->date(), m_endDateEdit->date()};
// }
// return {QDate(), QDate()};
//}
#include "MultiFunctionDialog.h"
#include "ui_MultiFunctionDialog.h"
#include <QStyleOption>
......@@ -249,20 +20,26 @@ MultiFunctionDialog::MultiFunctionDialog(DialogType type,QWidget *parent) :
// 弹窗基础设置
setWindowTitle("选择设置");
setFixedSize(1900, 700); // 修正:原1800x800太大,改为适配弹窗的尺寸(可按需调整)
move(40,440);
// setFixedSize(1900, 700); // 修正:原1800x800太大,改为适配弹窗的尺寸(可按需调整)
// move(40,440);
// 根据类型初始化对应的UI
switch (m_dialogType) {
case WorkStationType:
setWindowTitle("请选择要设置的工位");
setFixedSize(1900, 700); // 修正:原1800x800太大,改为适配弹窗的尺寸(可按需调整)
move(40,440);
initWorkStationUI();
break;
case DeviceType:
setWindowTitle("请选择设备名称");
setFixedSize(1900, 700); // 修正:原1800x800太大,改为适配弹窗的尺寸(可按需调整)
move(40,440);
initDeviceUI();
break;
case InspectionType:
setWindowTitle("请选择抽检项类型");
setFixedSize(1900, 700); // 修正:原1800x800太大,改为适配弹窗的尺寸(可按需调整)
move(40,440);
initInspectionUI();
break;
case TimeRangeType:
......@@ -275,7 +52,7 @@ MultiFunctionDialog::MultiFunctionDialog(DialogType type,QWidget *parent) :
MultiFunctionDialog::~MultiFunctionDialog()
{
delete ui;
//delete ui;
}
// -------------------------- 关键补充:重写paintEvent实现圆角(必须,否则弹窗圆角不生效) --------------------------
......@@ -305,15 +82,19 @@ void MultiFunctionDialog::initWorkStationUI() {
QListWidgetItem *item = m_listWidget->item(i);
item->setTextAlignment(Qt::AlignCenter); // 等同于 Qt::AlignHCenter | Qt::AlignVCenter
}
// // 开启循环滚动
// m_enableCycleScroll = true;
// // 给列表安装事件过滤器
// m_listWidget->installEventFilter(this);
// 列表样式
m_listWidget->setStyleSheet(R"(
QListWidget { border: none;
outline: none;
font-size: 40px;
font-size: 25px;
border-radius: 25px;
} /* 去掉列表边框 */
QListWidget::item {
padding: 12px; /* 选项内边距加大,更宽松 */
padding: 25px; /* 选项内边距加大,更宽松 */
text-align: center;
outline: none;
......@@ -364,9 +145,9 @@ void MultiFunctionDialog::initWorkStationUI() {
// 布局
QVBoxLayout *mainLayout = new QVBoxLayout(this);
// 布局内边距(避免内容贴弹窗边缘)
mainLayout->setContentsMargins(20, 20, 20, 20);
mainLayout->setContentsMargins(20, 30, 20, 20);
// 布局间距(控件之间的距离)
mainLayout->setSpacing(15);
mainLayout->setSpacing(25);
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->setSpacing(12); // 两个按钮之间的间距
......@@ -381,6 +162,32 @@ void MultiFunctionDialog::initWorkStationUI() {
connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
}
//// 事件过滤器实现:处理上下键循环滚动
//bool MultiFunctionDialog::eventFilter(QObject *watched, QEvent *event) {
// // 仅处理QListWidget的按键事件,且开启了循环滚动
// if (watched == m_listWidget && m_enableCycleScroll && event->type() == QEvent::KeyPress) {
// QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
// int currentRow = m_listWidget->currentRow();
// int itemCount = m_listWidget->count();
// // 按下下键:最后一项 -> 第一项
// if (keyEvent->key() == Qt::Key_Down) {
// if (currentRow == itemCount - 1) {
// m_listWidget->setCurrentRow(0);
// return true; // 拦截默认事件,避免继续向下滚动
// }
// }
// // 按上键:第一项 -> 最后一项
// else if (keyEvent->key() == Qt::Key_Up) {
// if (currentRow == 0) {
// m_listWidget->setCurrentRow(itemCount - 1);
// return true; // 拦截默认事件
// }
// }
// }
// // 其他事件交给父类处理
// return QDialog::eventFilter(watched, event);
//}
// -------------------------- 2. 初始化设备选择UI(按钮样式同步修改) --------------------------
void MultiFunctionDialog::initDeviceUI() {
......@@ -556,7 +363,7 @@ QString MultiFunctionDialog::getStringResult() const {
switch (m_dialogType) {
case WorkStationType:
// 返回选中的工位
if (m_listWidget->currentItem()) {
if (m_listWidget &&m_listWidget->currentItem()) {
return m_listWidget->currentItem()->text();
}
break;
......
......@@ -11,6 +11,7 @@
#include <QCalendarWidget> // 用到了 QCalendarWidget
#include <QVBoxLayout> // 用到了布局
#include <QHBoxLayout>
#include <QKeyEvent> // 新增:包含QKeyEvent头文件
// 枚举:4种弹窗类型
enum DialogType {
WorkStationType, // 工位选择
......@@ -33,6 +34,9 @@ public:
// 统一接口:获取选择结果(根据类型返回对应数据)
QString getStringResult() const; // 用于:工位/设备/抽检项(返回字符串)
QPair<QDate, QDate> getTimeRangeResult() const; // 用于:时间范围(返回日期对)
private slots:
// 事件过滤器:处理QListWidget的按键事件(实现循环滚动)
// bool eventFilter(QObject *watched, QEvent *event);
private:
// 根据类型创建对应的UI
void initWorkStationUI(); // 初始化工位选择UI
......@@ -46,6 +50,7 @@ private:
QButtonGroup *m_radioGroup; // 单选按钮组(抽检项用)
QDateEdit *m_startDateEdit; // 开始日期编辑框(时间用)
QDateEdit *m_endDateEdit; // 结束日期编辑框(时间用)
// bool m_enableCycleScroll = false;
Ui::MultiFunctionDialog *ui;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2025-12-03T10:14:14. -->
<!-- Written by QtCreator 4.11.1, 2025-12-03T15:06:26. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -7,8 +7,8 @@ carMachineDetectionWidget::carMachineDetectionWidget(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::carMachineDetectionWidget)
{
setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint);
setMaximumSize(2000, 1200);
//setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint);
//setMaximumSize(2000, 1200);
ui->setupUi(this);
//初始状态
// ui->widget_search->hide();
......@@ -72,3 +72,18 @@ void carMachineDetectionWidget::on_pushButton_inspectionItemt_clicked()
}
}
}
void carMachineDetectionWidget::on_pushButton_chooseTime_clicked()
{
MultiFunctionDialog dialog(TimeRangeType, this);
if (dialog.exec() == QDialog::Accepted) {
QPair<QDate, QDate> timeRange = dialog.getTimeRangeResult();
QDate startDate = timeRange.first;
QDate endDate = timeRange.second;
if (startDate.isValid() && endDate.isValid()) {
QMessageBox::information(this, "选择结果",
QString("时间范围:%1 至 %2").arg(startDate.toString("yyyy-MM-dd")).arg(endDate.toString("yyyy-MM-dd")));
// 业务逻辑:更新时间范围设置
}
}
}
......@@ -28,6 +28,8 @@ private slots:
void on_pushButton_inspectionItemt_clicked();
void on_pushButton_chooseTime_clicked();
private:
Ui::carMachineDetectionWidget *ui;
};
......
......@@ -473,6 +473,12 @@
<height>191</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
......@@ -1432,7 +1438,7 @@ QWidget#widget_SearchCriteria {
<widget class="QLabel" name="label_choosetime">
<property name="geometry">
<rect>
<x>100</x>
<x>170</x>
<y>10</y>
<width>141</width>
<height>51</height>
......@@ -1673,37 +1679,9 @@ QLineEdit#lineEdit_Model {
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>140</x>
<y>699</y>
<width>800</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>1010</x>
<y>700</y>
<width>800</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<zorder>listWidget</zorder>
<zorder>tabWidget</zorder>
<zorder>pushButton_btnSoftwareControl</zorder>
<zorder>pushButton</zorder>
<zorder>pushButton_2</zorder>
</widget>
<widget class="QWidget" name="SoftControlwidget" native="true">
<property name="geometry">
......@@ -1811,6 +1789,12 @@ QLabel#label_softwnamet {
</item>
<item>
<widget class="QWidget" name="widget_ReleaseTime" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">/* widget_SearchCriteria 样式:背景色+圆角 */
QWidget#widget_ReleaseTime {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment