活动介绍

QAction样式 设置左间距

时间: 2024-05-04 22:18:45 浏览: 132
你可以使用QAction的setStyleSheet()方法来设置样式,具体可以参考以下代码示例: ``` QAction *action = new QAction("Example", this); action->setStyleSheet("padding-left: 20px;"); ``` 在样式表中,使用`padding-left`属性可以设置左侧间距的大小。你可以根据需要调整数值。
相关问题

Qt 5.13 QAction样式 设置左间距无效

如果你想要在 `QAction` 中设置左间距,可以使用样式表的方式来实现: ``` QAction { padding-left: 20px; } ``` 这将在 `QAction` 左侧设置 20 像素的间距。如果你已经尝试过这种方法但是无效,可能是因为样式表被其他样式所覆盖,或者 `QAction` 的 `autoRepeat` 属性设置为 `true`,这将导致样式表无效。你可以尝试使用更具体的选择器来覆盖其他样式,或者将 `autoRepeat` 设置为 `false`。

QAction 设置左间距

可以使用 `QAction` 的 `setIconText` 方法来设置左侧的文本,并且可以通过设置 `QAction` 的样式表来设置左侧文本的间距。示例代码如下: ```python action = QAction("My Action", self) action.setIconText(" My Action") # 设置左侧文本并添加空格 action.setStyleSheet("padding-left: 20px;") # 设置左侧间距 ``` 在这个示例中,我们首先使用 `setIconText` 方法设置了 `QAction` 的左侧文本,并在此文本前添加了一些空格。然后,使用 `setStyleSheet` 方法设置了 `QAction` 的样式表,其中 `padding-left` 属性设置了左侧的间距为 20 像素。
阅读全文

相关推荐

#include "mainwindow.h" #include "ui_mainwindow.h" #include <QHBoxLayout> #include <QVBoxLayout> #include <QMessageBox> #include <QGroupBox> #include <QFormLayout> #include <QPixmap> #include <QSerialPortInfo> #include <QDateTime> #include <windows.h> #include <dwmapi.h> #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 #endif MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_serialWorker(nullptr) , timeoutTimer(new QTimer(this)) , currentActiveButton(nullptr) , workModeButton(nullptr) , m_isHandshakeSuccess(false) , sensorVoltageTimer(new QTimer(this)) , isGettingSensorVoltage(false) , m_isCISChecking(false) , m_agingTimer(new QTimer(this)) { this->setStyleSheet("QMainWindow{background-color:#F6F6F2;}"); if(HWND hwnd = (HWND)winId()) { BOOL darkMode = FALSE; DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &darkMode, sizeof(darkMode)); } ui->setupUi(this); setWindowTitle(tr("点钞机")); setMinimumSize(800, 600); //主布局-左右分割1:3 mainLayout = new QHBoxLayout(); mainLayout->setSpacing(10); mainLayout->setStretch(0, 1); //左侧区域 mainLayout->setStretch(1, 2); //中间区域 mainLayout->setStretch(2, 1); //右侧区域 //========== 左侧区域 ========== QWidget *leftWidget = new QWidget(); QVBoxLayout *leftLayout = new QVBoxLayout(leftWidget); leftLayout->setSpacing(10); QGroupBox *portGroup = new QGroupBox(tr("串口设置")); portGroup->setStyleSheet("QGroupBox { background-color: #F6F6F2; border: 1px solid #ccc; border-radius: 5px; margin-top: 10px;color:#388087; font-weight: bold; }" "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 3px; background-color:#F6F6F2;font-weight: bold; }"); QVBoxLayout *portLayout = new QVBoxLayout(portGroup); portComboBox = new QComboBox(portGroup); portComboBox->setStyleSheet("background-color:#ebebe7;color:#388087;font-weight: bold; "); //波特率选择下拉框 baudRateComboBox = new QComboBox(portGroup); baudRateComboBox->setStyleSheet("background-color:#ebebe7;color:#388087;font-weight: bold; "); baudRateComboBox->addItem("115200", QSerialPort::Baud115200); baudRateComboBox->addItem("9600", QSerialPort::Baud9600); baudRateComboBox->setCurrentIndex(0); //默认115200 currentBaudRate = QSerialPort::Baud115200; //连接波特率变化信号 connect(baudRateComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::onBaudRateChanged); btnRefreshPorts = new QPushButton("刷新串口", portGroup); btnRefreshPorts->setStyleSheet("QPushButton {" "background-color:#e0e0e0;" "color:#388087;" "font-weight: bold;" "}" "QPushButton:hover{""background-color: #e0e0e0;color:#388087;" "}" "QPushButton:pressed {" "background-color: #a0a0a0;" "color:#388087;" "}"); btnConnect = new QPushButton("连接串口", portGroup); btnConnect->setStyleSheet("QPushButton {" "background-color:#e0e0e0;" "color:#388087;" "font-weight: bold;" "}" "QPushButton:hover{""background-color: #e0e0e0;color:#388087;" "}" "QPushButton:pressed {" "background-color: #a0a0a0;" "color:#388087;" "}"); portLayout->addWidget(portComboBox); portLayout->addWidget(baudRateComboBox); //添加波特率下拉框 portLayout->addWidget(btnRefreshPorts); portLayout->addWidget(btnConnect); portLayout->setStretch(0, 1); portLayout->setStretch(1, 1); portLayout->setStretch(2, 1); portLayout->setStretch(3, 1); leftLayout->addWidget(portGroup,2); QGroupBox *infoGroup = new QGroupBox("机器信息"); infoGroup->setStyleSheet("background-color:#F6F6F2;color:#388087;border: 1px solid #ccc;padding: 5px;font-weight: bold; "); QVBoxLayout *infoLayout = new QVBoxLayout(infoGroup); machineInfoLineEdit = new QTextEdit(); machineInfoLineEdit->setReadOnly(true); machineInfoLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QFont font; font.setPointSize(12); machineInfoLineEdit->setFont(font); //设置行间距 machineInfoLineEdit->setStyleSheet( "QTextEdit {" " line-height: 150%;" " background-color: #F6F6F2;" " border: 1px solid #ccc;" " padding: 5px;" " color: black;" " font-weight: bold; " "}" ); machineInfoLineEdit->setLineWrapMode(QTextEdit::WidgetWidth); machineInfoLineEdit->setWordWrapMode(QTextOption::WrapAnywhere); //machineInfoLineEdit->setMinimumHeight(200); machineInfoLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); infoLayout->addWidget(machineInfoLineEdit); leftLayout->addWidget(infoGroup, 3); //-------------计数显示区域-------------- CountingInfoWidget *countingWidget = new CountingInfoWidget(); QVBoxLayout *countLayout = new QVBoxLayout(countingWidget); countLayout->setSpacing(10); countLayout->setContentsMargins(10, 10, 10, 10); countLayout->setStretch(0, 3); //表格区域 countLayout->setStretch(1, 1); //按钮区域 //创建并配置表格 denominationTable = new QTableWidget(countingWidget); denominationTable->setObjectName("denominationTable"); denominationTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); denominationTable->setColumnCount(3); //金额、数量、单位 denominationTable->setRowCount(0); denominationTable->verticalHeader()->setVisible(false); //隐藏行头 denominationTable->horizontalHeader()->setVisible(false); //隐藏列头 denominationTable->setShowGrid(false); //隐藏网格线 denominationTable->setEditTriggers(QAbstractItemView::NoEditTriggers); //禁止编辑 denominationTable->setSelectionMode(QAbstractItemView::NoSelection); //禁止选择 denominationTable->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); //固定大小 //设置表格样式 denominationTable->setStyleSheet( "QTableWidget {" " background-color: transparent;" " border: none;" " color: #388087;" "}" "QTableWidget::item {" " padding: 2px;" " border: none;" "}" ); //设置列宽 denominationTable->setColumnWidth(0, 80); //金额列 denominationTable->setColumnWidth(1, 40); //数量列 denominationTable->setColumnWidth(2, 40); //单位列 //将表格添加到布局 //countLayout->addWidget(denominationTable, 3, Qt::AlignLeft | Qt::AlignTop); connect(countingWidget, &CountingInfoWidget::blankAreaClicked, this, &MainWindow::onAmountLabelClicked); //主布局:上部显示区域和下部按钮 QHBoxLayout *mainCountLayout = new QHBoxLayout(); //左侧布局 - 退钞数 QVBoxLayout *refundLayout = new QVBoxLayout(); QLabel* refundTitleLabel = new QLabel("退钞数"); //refundTitleLabel->setFixedWidth(120); refundTitleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); refundTitleLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;font:14px;border: none;font-weight: bold; "); refundTitleLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); refundLabel = new ClickableLabel(); // refundLabel->setFixedWidth(90); refundLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); refundLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;padding: 5px;border: none;font:bold 17px;font-weight: bold; "); refundLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); //添加SN显示label QHBoxLayout *refundRowLayout = new QHBoxLayout(); //refundRowLayout->addWidget(refundLabel); snLabel = new QLabel(); snLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;padding: 5px;border: none;font:bold 12px;font-weight: bold; "); snLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); snLabel->setMinimumWidth(150); //为SN留出足够空间 refundRowLayout->addWidget(refundTitleLabel); refundRowLayout->addWidget(snLabel); refundLayout->addWidget(denominationTable, 1); refundLayout->addLayout(refundRowLayout,0); refundLayout->addWidget(refundLabel,0); //使用水平布局替代直接添加refundLabel //中间布局-弹性空间 QSpacerItem *spacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); //右侧布局-包含金额和张数 QVBoxLayout *rightcountLayout = new QVBoxLayout(); //金额部分 QVBoxLayout *amountLayout = new QVBoxLayout(); QLabel* amountTitleLabel = new QLabel("金额"); amountTitleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); amountTitleLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;font:14px;border: none;font-weight: bold; "); amountTitleLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); amountLabel = new ClickableLabel(); amountLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;padding: 5px;border: none;font:bold 17px;font-weight: bold; "); amountLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); amountLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); amountLayout->addStretch(); //弹性空间使金额靠右 amountLayout->addWidget(amountTitleLabel); amountLayout->addWidget(amountLabel); rightcountLayout->addLayout(amountLayout); rightcountLayout->addStretch(); //张数部分 QVBoxLayout *sheetLayout = new QVBoxLayout(); QLabel* sheetTitleLabel = new QLabel("张数"); sheetTitleLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;font:14px;border: none;font-weight: bold; "); sheetTitleLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); sheetNumberLabel = new ClickableLabel(); sheetNumberLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;padding: 5px;border: none;font:bold 17px;font-weight: bold; "); sheetNumberLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); sheetTitleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sheetNumberLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); sheetLayout->addStretch(); //弹性空间使张数靠右 sheetLayout->addWidget(sheetTitleLabel); sheetLayout->addWidget(sheetNumberLabel); rightcountLayout->addLayout(sheetLayout); refundLabel->setText("0"); amountLabel->setText("0"); sheetNumberLabel->setText("0"); //设置标签可点击 refundLabel->setCursor(Qt::PointingHandCursor); amountLabel->setCursor(Qt::PointingHandCursor); sheetNumberLabel->setCursor(Qt::PointingHandCursor); //将各部分添加到主布局 mainCountLayout->addLayout(refundLayout,1); mainCountLayout->addItem(spacer); mainCountLayout->addLayout(rightcountLayout,1); //连接点击信号 connect(refundLabel, &ClickableLabel::clicked, this, &MainWindow::onRefundLabelClicked); connect(amountLabel, &ClickableLabel::clicked, this, &MainWindow::onAmountLabelClicked); connect(sheetNumberLabel, &ClickableLabel::clicked, this, &MainWindow::onSheetNumberLabelClicked); //将主显示布局添加到计数组 countLayout->addLayout(mainCountLayout,2); buttonStyle = "QPushButton {" "background-color: #f8f8f8;" "border: 1px solid #ccc;" "border-radius: 5px;" "padding: 8px;" "width: 120px;" "height: 50px;" "color:#388087;" "font-weight: bold; " "}" "QPushButton:hover {" "background-color: #f0f0f0;" "color:#388087;" "font-weight: bold; " "}" "QPushButton:pressed {" "background-color: #c0c0c0;" "color:#388087;" "font-weight: bold; " "}"; //添加重置按钮 resetCountButton = new QPushButton("重置计数"); resetCountButton->setStyleSheet(buttonStyle); resetCountButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); connect(resetCountButton, &QPushButton::clicked, this,&MainWindow::on_resetCountButton_clicked); countLayout->addWidget(resetCountButton); leftLayout->addWidget(countingWidget, 3); mainLayout->addWidget(leftWidget, 1); //========== 中间区域 ========== QWidget *centerWidget = new QWidget(); QVBoxLayout *centerLayout = new QVBoxLayout(centerWidget); centerLayout->setSpacing(10); //机器状态区域 QGroupBox *statusGroup = new QGroupBox("机器状态"); statusGroup->setStyleSheet("QGroupBox { background-color: #F6F6F2; border: 1px solid #ccc; border-radius: 5px; margin-top: 10px;color:#388087; font-weight: bold; }" "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 3px; background-color:#F6F6F2;font-weight: bold; }"); QHBoxLayout *statusLayout = new QHBoxLayout(statusGroup); machineStatusImage = new QLabel(); machineStatusImage->setAlignment(Qt::AlignCenter); machineStatusImage->setScaledContents(true); machineStatusImage->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // QLabel* overlayLabel = new QLabel(machineStatusImage); // overlayLabel->setStyleSheet("background-color: transparent; color: red; font-weight: bold;"); // overlayLabel->setText("QT"); // overlayLabel->move(250, 110); // 设置位置 // overlayLabel->adjustSize(); // overlayLabel->setAttribute(Qt::WA_TransparentForMouseEvents); // 允许点击穿透 voltageTable = new QTableWidget(); voltageTable->setColumnCount(3); //voltageTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); voltageTable->setHorizontalHeaderLabels({"传感器ID", "传感器名称", "电压值(V)"}); voltageTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); voltageTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); voltageTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); voltageTable->setStyleSheet( "QTableWidget {" " background-color: #F6F6F2;" " border: 1px solid #ccc;" " color: #388087;" "}" "QTableWidget::item {" " padding: 2px;" " border: none;" " background-color: #F6F6F2;" " color: #388087;" "}" "QTableWidget::item:selected {" " background-color: #F6F6F2;" " color: #388087;" "}" "QHeaderView {" " background-color: #F6F6F2;" //表头整体背景色 "}" "QScrollBar:vertical {" " background: #F6F6F2;" " width: 12px;" " margin: 0px 0px 0px 0px;" "}" "QHeaderView::section {" " background-color: #F6F6F2;" " padding: 4px;" " border: 1px solid #ccc;" " color: #388087;" "}" "QTableCornerButton::section {" " background-color: #F6F6F2;" //左上角空白区域 " border: 1px solid #ccc;" "}" ); voltageTable->setVisible(false); //初始隐藏表格 QPixmap pixmap(":/image/333.svg"); if(!pixmap.isNull()) { machineStatusImage->setMaximumSize(450, 700); QPixmap scaled = pixmap.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); machineStatusImage->setPixmap(scaled); } else { machineStatusImage->setText("图片加载失败"); } statusLayout->addWidget(machineStatusImage, 3); statusLayout->addWidget(voltageTable, 1); centerLayout->addWidget(statusGroup, 3); //信息显示区域 QGroupBox *messageGroup = new QGroupBox(); messageGroup->setStyleSheet("background-color:#F6F6F2;color:#388087;border: 1px solid #ccc;padding: 5px;font-weight: bold; "); QVBoxLayout *messageLayout = new QVBoxLayout(messageGroup); //添加顶部布局,包含标题和清除按钮 QHBoxLayout *messageHeaderLayout = new QHBoxLayout(); QLabel *messageTitleLabel = new QLabel("信息显示"); messageTitleLabel->setStyleSheet("background-color:#F6F6F2;color:#388087;font-weight: bold;"); QPushButton *clearButton = new QPushButton("清空"); clearButton->setStyleSheet("QPushButton {" "background-color: #f0f0f0;" "border: 1px solid #ccc;" "border-radius: 3px;" "padding: 3px 8px;" "color:#388087;" "font-weight: bold;" "}" "QPushButton:hover {" "background-color: #e0e0e0;" "}" "QPushButton:pressed {" "background-color: #a0a0a0;" "}"); clearButton->setFixedWidth(60); //设置固定宽度 messageHeaderLayout->addWidget(messageTitleLabel); messageHeaderLayout->addStretch(); messageHeaderLayout->addWidget(clearButton); messageLayout->addLayout(messageHeaderLayout); messageTextEdit = new QTextEdit(); messageTextEdit->setReadOnly(true); messageTextEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); messageTextEdit->setStyleSheet("QTextEdit { background-color: #F6F6F2; border: 1px solid #ccc; padding: 5px; color:black;font-weight: bold;/* font-family:宋体; */font-size:14px;}"); messageLayout->addWidget(messageTextEdit); //连接清除按钮的信号 connect(clearButton, &QPushButton::clicked, this, [this](){ messageTextEdit->clear(); }); centerLayout->addWidget(messageGroup, 2); mainLayout->addWidget(centerWidget, 2); //========== 右侧区域 ========== QWidget *rightWidget = new QWidget(); QVBoxLayout *rightLayout = new QVBoxLayout(rightWidget); rightLayout->setSpacing(10); //按钮区域 QGroupBox *buttonGroup = new QGroupBox("操作命令"); buttonGroup->setStyleSheet("QGroupBox { background-color: #F6F6F2; border: 1px solid #ccc black; border-radius: 5px; margin-top: 10px;color:#388087; font-weight: bold; }" "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 3px; background-color:#F6F6F2;font-weight: bold; }"); QVBoxLayout *buttonLayout = new QVBoxLayout(buttonGroup); commandStack = new QStackedWidget(); commandStack->addWidget(createFirstCommandPage()); //第一页 commandStack->addWidget((createSecondCommandPage())); //第二页 //添加导航按钮 QHBoxLayout* navLayout = new QHBoxLayout(); addNavigationButtons(navLayout); buttonLayout->addLayout(navLayout); buttonLayout->addWidget(commandStack); rightLayout->addWidget(buttonGroup); mainLayout->addWidget(rightWidget, 1); //设置中心窗口 QWidget *centralWidget = new QWidget(); centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); // QToolBar* langToolBar = addToolBar(tr("语言")); // QAction* zhAction = langToolBar->addAction("中文"); // QAction* enAction = langToolBar->addAction("英语"); // connect(zhAction, &QAction::triggered, this, [this]() { // loadLanguage("zh_CN"); // }); // connect(enAction, &QAction::triggered, this, [this]() { // loadLanguage("en"); // }); //连接信号槽 connect(btnRefreshPorts, &QPushButton::clicked, this, &MainWindow::refreshPorts); connect(btnConnect, &QPushButton::clicked, this, &MainWindow::toggleConnection); //初始化UI状态 refreshPorts(); enableControls(false); initializeErrorMaps(); //初始化传感器名称映射 sensorNameMap["0X01"] = "QTH"; sensorNameMap["0X02"] = "QTL"; sensorNameMap["0X03"] = "PS1L"; sensorNameMap["0X04"] = "PS1M"; sensorNameMap["0X05"] = "PS1R"; sensorNameMap["0X06"] = "PS2L"; sensorNameMap["0X07"] = "PS2R"; sensorNameMap["0X08"] = "PS3L"; sensorNameMap["0X09"] = "PS3M"; sensorNameMap["0X0A"] = "PS3R"; sensorNameMap["0X0B"] = "ST"; sensorNameMap["0X0C"] = "STL"; sensorNameMap["0X0D"] = "STR"; sensorNameMap["0X0E"] = "STU"; sensorNameMap["0X0F"] = "PS4"; sensorNameMap["0X10"] = "UV1"; sensorNameMap["0X11"] = "UV2"; sensorNameMap["0X12"] = "DWP"; sensorNameMap["0X13"] = "RJH"; sensorNameMap["0X14"] = "RJL"; sensorNameMap["0X15"] = "BTU"; sensorNameMap["0X16"] = "BTD"; sensorNameMap["0X17"] = "CVU"; sensorNameMap["0X18"] = "CVD"; sensorNameMap["0X19"] = "UVM"; sensorNameMap["0X1A"] = "SAFE"; sensorNameMap["0X1B"] = "PS5"; sensorNameMap["0X1C"] = "TKL"; sensorNameMap["0X1D"] = "TKR"; sensorNameMap["0X1E"] = "QTLoc"; sensorNameMap["0X1F"] = "TDLoc"; sensorNameMap["0X20"] = "RJLoc"; sensorNameMap["0X21"] = "FL"; sensorNameMap["0X22"] = "Chn"; //老化定时器 connect(m_agingTimer, &QTimer::timeout, this, [this]() { m_agingSeconds++; updateAgingTimeDisplay(); }); } MainWindow::~MainWindow() { //清理串口工作线程 if(m_serialWorker) { m_serialWorker->stop(); //停止线程 m_serialWorker->wait(); delete m_serialWorker; m_serialWorker = nullptr; } delete ui; } //波特率改变处理 void MainWindow::onBaudRateChanged(int index) { currentBaudRate = baudRateComboBox->currentData().toInt(); //如果已连接,则更新波特率 if(m_serialWorker) { m_serialWorker->setBaudRate(currentBaudRate); logMessage(QString("波特率已更改为: %1").arg(baudRateComboBox->currentText())); } } void MainWindow::onRefundLabelClicked() { if(!m_serialWorker) { logMessage("串口未打开"); return; } //清空之前的退钞数据 m_rejectList.clear(); m_rejectReasons.clear(); if(m_rejectDialog && m_rejectDialog->isVisible()) { m_rejectDialog->close(); } //初始化对话框 initRejectDialog(); //发送获取退钞口信息列表命令 sendGetRejectListCommand(); setButtonActive(rejectListButton); } void MainWindow::onAmountLabelClicked() { if(!m_serialWorker) { logMessage("串口未打开"); return; } //清空之前的明细数据 m_detailList.clear(); initDetailDialog(); sendDetailedlistCommand(); setButtonActive(detailedlistButton); } void MainWindow::onSheetNumberLabelClicked() { onAmountLabelClicked(); } QWidget* MainWindow::createFirstCommandPage() { QWidget *page = new QWidget(); QGridLayout *grid = new QGridLayout(page); grid->setSpacing(10); grid->setContentsMargins(10, 10, 10, 10); buttonStyle = "QPushButton {" "background-color: #f8f8f8;" "border: 1px solid #ccc;" "border-radius: 5px;" "padding: 8px;" "width: 120px;" "height: 50px;" "color:#388087;" "font-weight: bold; " "}" "QPushButton:hover {" "background-color: #f0f0f0;" "color:#388087;" "font-weight: bold; " "}" "QPushButton:pressed {" "background-color: #c0c0c0;" "color:#388087;" "font-weight: bold; " "}"; QWidget *handshakeWidget = new QWidget(); QVBoxLayout *handshakeLayout = new QVBoxLayout(handshakeWidget); handshakeLayout->setContentsMargins(0, 0, 0, 0); handshakeLayout->setSpacing(2); QLabel *emptyLabel3 = new QLabel(); emptyLabel3->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel3->setAlignment(Qt::AlignLeft | Qt::AlignBottom); handshakeLayout->addWidget(emptyLabel3); QPushButton *handshakeButton = new QPushButton("握手命令"); handshakeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); handshakeButton->setStyleSheet(buttonStyle); handshakeLayout->addWidget(handshakeButton); grid->addWidget(handshakeWidget, 0, 0); QWidget *testWidget = new QWidget(); QVBoxLayout *testLayout = new QVBoxLayout(testWidget); testLayout->setContentsMargins(0, 0, 0, 0); testLayout->setSpacing(2); QLabel *emptyLabel4 = new QLabel(); emptyLabel4->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel4->setAlignment(Qt::AlignLeft | Qt::AlignBottom); testLayout->addWidget(emptyLabel4); QPushButton *testButton = new QPushButton("获取软件版本信息"); testButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); testButton->setStyleSheet(buttonStyle); testLayout->addWidget(testButton); grid->addWidget(testWidget, 0, 1); //启动机器按钮 QWidget *startMachineWidget = new QWidget(); QVBoxLayout *startMachineLayout = new QVBoxLayout(startMachineWidget); startMachineLayout->setContentsMargins(0, 0, 0, 0); startMachineLayout->setSpacing(2); QLabel *startMachineLabel = new QLabel("机器控制"); startMachineLabel->setStyleSheet("color:#388087; font-weight: bold;"); startMachineLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); startMachineLayout->addWidget(startMachineLabel); startMachineButton = new QPushButton("启动机器"); startMachineButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); startMachineButton->setStyleSheet(buttonStyle); startMachineLayout->addWidget(startMachineButton); grid->addWidget(startMachineWidget, 1, 0); //设置手动/自动启动 QWidget *handleSelfWidget = new QWidget(); QVBoxLayout *handleSelfLayout = new QVBoxLayout(handleSelfWidget); handleSelfLayout->setContentsMargins(0, 0, 0, 0); handleSelfLayout->setSpacing(2); QLabel *handleSelfLabel = new QLabel("手动/自动启动"); handleSelfLabel->setStyleSheet("color:#388087; font-weight: bold;"); handleSelfLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); handleSelfLayout->addWidget(handleSelfLabel); handleSelfButton = new QPushButton("设置手动/自动启动"); handleSelfButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); handleSelfButton->setStyleSheet(buttonStyle); handleSelfLayout->addWidget(handleSelfButton); grid->addWidget(handleSelfWidget, 1, 1); //工作模式按钮 QWidget *workModeWidget = new QWidget(); QVBoxLayout *workModeLayout = new QVBoxLayout(workModeWidget); workModeLayout->setContentsMargins(0, 0, 0, 0); workModeLayout->setSpacing(2); QLabel *workModeLabel = new QLabel("工作模式"); workModeLabel->setStyleSheet("color:#388087; font-weight: bold;"); workModeLayout->addWidget(workModeLabel); workModeLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); workModeButton = new QPushButton("选择工作模式"); workModeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); workModeButton->setStyleSheet(buttonStyle); // workModeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); workModeLayout->addWidget(workModeButton); grid->addWidget(workModeWidget, 2, 0); QWidget *currencyWidget = new QWidget(); QVBoxLayout *currencyLayout = new QVBoxLayout(currencyWidget); currencyLayout->setContentsMargins(0, 0, 0, 0); currencyLayout->setSpacing(2); QLabel *currencyLabel = new QLabel("货币币种"); currencyLabel->setStyleSheet("color:#388087; font-weight: bold;"); currencyLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); currencyLayout->addWidget(currencyLabel); currencyButton = new QPushButton("获取货币币种"); currencyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); currencyButton->setStyleSheet(buttonStyle); currencyLayout->addWidget(currencyButton); grid->addWidget(currencyWidget, 2, 1); //预置数按钮 QWidget *presetWidget = new QWidget(); QVBoxLayout *presetLayout = new QVBoxLayout(presetWidget); presetLayout->setContentsMargins(0, 0, 0, 0); presetLayout->setSpacing(2); QLabel *presetLabel = new QLabel("预置数"); presetLabel->setStyleSheet("color:#388087; font-weight: bold;"); presetLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); presetLayout->addWidget(presetLabel); presetButton = new QPushButton("设置预置数"); presetButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); presetButton->setStyleSheet(buttonStyle); presetLayout->addWidget(presetButton); grid->addWidget(presetWidget, 3, 0); //预置金额按钮 QWidget *presetAmountWidget = new QWidget(); QVBoxLayout *presetAmountLayout = new QVBoxLayout(presetAmountWidget); presetAmountLayout->setContentsMargins(0, 0, 0, 0); presetAmountLayout->setSpacing(2); QLabel *presetAmountLabel = new QLabel("预置金额"); presetAmountLabel->setStyleSheet("color:#388087; font-weight: bold;"); presetAmountLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); presetAmountLayout->addWidget(presetAmountLabel); presetAmountButton = new QPushButton("设置预置金额"); presetAmountButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); presetAmountButton->setStyleSheet(buttonStyle); presetAmountLayout->addWidget(presetAmountButton); grid->addWidget(presetAmountWidget, 3, 1); //走钞速度按钮 QWidget *speedWidget = new QWidget(); QVBoxLayout *speedLayout = new QVBoxLayout(speedWidget); speedLayout->setContentsMargins(0, 0, 0, 0); speedLayout->setSpacing(2); QLabel *speedLabel = new QLabel("走钞速度"); speedLabel->setStyleSheet("color:#388087; font-weight: bold;"); speedLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); speedLayout->addWidget(speedLabel); speedButton = new QPushButton("设置机器走钞速度"); speedButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); speedButton->setStyleSheet(buttonStyle); speedLayout->addWidget(speedButton); grid->addWidget(speedWidget, 4, 0); //版本清分按钮 QWidget *versionSortWidget = new QWidget(); QVBoxLayout *versionSortLayout = new QVBoxLayout(versionSortWidget); versionSortLayout->setContentsMargins(0, 0, 0, 0); versionSortLayout->setSpacing(2); QLabel *versionSortLabel = new QLabel("版本清分"); versionSortLabel->setStyleSheet("color:#388087; font-weight: bold;"); versionSortLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); versionSortLayout->addWidget(versionSortLabel); versionSortButton = new QPushButton("设置版本清分"); versionSortButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); versionSortButton->setStyleSheet(buttonStyle); versionSortLayout->addWidget(versionSortButton); grid->addWidget(versionSortWidget, 4, 1); //退钞口张数按钮 QWidget *rejectCountWidget = new QWidget(); QVBoxLayout *rejectCountLayout = new QVBoxLayout(rejectCountWidget); rejectCountLayout->setContentsMargins(0, 0, 0, 0); rejectCountLayout->setSpacing(2); QLabel *rejectCountLabel = new QLabel("退钞口张数"); rejectCountLabel->setStyleSheet("color:#388087; font-weight: bold;"); rejectCountLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); rejectCountLayout->addWidget(rejectCountLabel); rejectCountButton = new QPushButton("设置退钞口张数"); rejectCountButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); rejectCountButton->setStyleSheet(buttonStyle); rejectCountLayout->addWidget(rejectCountButton); grid->addWidget(rejectCountWidget, 5, 0); //查询货币组合按钮 QWidget *queryCurrencyWidget = new QWidget(); QVBoxLayout *queryCurrencyLayout = new QVBoxLayout(queryCurrencyWidget); queryCurrencyLayout->setContentsMargins(0, 0, 0, 0); queryCurrencyLayout->setSpacing(2); QLabel *queryCurrencyLabel = new QLabel("货币组合"); queryCurrencyLabel->setStyleSheet("color:#388087; font-weight: bold;"); queryCurrencyLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); queryCurrencyLayout->addWidget(queryCurrencyLabel); queryCurrencyButton = new QPushButton("查询货币组合"); queryCurrencyButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); queryCurrencyButton->setStyleSheet(buttonStyle); queryCurrencyLayout->addWidget(queryCurrencyButton); grid->addWidget(queryCurrencyWidget, 5, 1); QWidget *detailedListWidget = new QWidget(); QVBoxLayout *detailedListLayout = new QVBoxLayout(detailedListWidget); detailedListLayout->setContentsMargins(0, 0, 0, 0); detailedListLayout->setSpacing(2); QLabel *emptyLabel8 = new QLabel("明细列表"); emptyLabel8->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel8->setAlignment(Qt::AlignLeft | Qt::AlignBottom); detailedListLayout->addWidget(emptyLabel8); detailedlistButton = new QPushButton("获取明细列表"); detailedlistButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); detailedlistButton->setStyleSheet(buttonStyle); detailedListLayout->addWidget(detailedlistButton); grid->addWidget(detailedListWidget, 6, 0); QWidget *rejectListWidget = new QWidget(); QVBoxLayout *rejectListLayout = new QVBoxLayout(rejectListWidget); rejectListLayout->setContentsMargins(0, 0, 0, 0); rejectListLayout->setSpacing(2); QLabel *emptyLabel7 = new QLabel("退钞口信息列表"); emptyLabel7->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel7->setAlignment(Qt::AlignLeft | Qt::AlignBottom); rejectListLayout->addWidget(emptyLabel7); rejectListButton = new QPushButton("获取退钞口信息列表"); rejectListButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); rejectListButton->setStyleSheet(buttonStyle); rejectListLayout->addWidget(rejectListButton); grid->addWidget(rejectListWidget, 6, 1); //获取传感器电压 QWidget *SensorvoltageWidget = new QWidget(); QVBoxLayout *SensorvoltageLayout = new QVBoxLayout(SensorvoltageWidget); SensorvoltageLayout->setContentsMargins(0, 0, 0, 0); SensorvoltageLayout->setSpacing(2); QLabel *SensorvoltageLabel = new QLabel("传感器电压"); SensorvoltageLabel->setStyleSheet("color:#388087; font-weight: bold;"); SensorvoltageLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); SensorvoltageLayout->addWidget(SensorvoltageLabel); SensorvoltageButton = new QPushButton("获取传感器电压"); SensorvoltageButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); SensorvoltageButton->setStyleSheet(buttonStyle); SensorvoltageLayout->addWidget(SensorvoltageButton); grid->addWidget(SensorvoltageWidget, 7, 0); //防钓鱼传感器按钮 QWidget *antiFishWidget = new QWidget(); QVBoxLayout *antiFishLayout = new QVBoxLayout(antiFishWidget); antiFishLayout->setContentsMargins(0, 0, 0, 0); antiFishLayout->setSpacing(2); QLabel *antiFishLabel = new QLabel("防钓鱼"); antiFishLabel->setStyleSheet("color:#388087; font-weight: bold;"); antiFishLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); antiFishLayout->addWidget(antiFishLabel); ansiFishButton = new QPushButton("防钓鱼传感器"); ansiFishButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); ansiFishButton->setStyleSheet(buttonStyle); antiFishLayout->addWidget(ansiFishButton); grid->addWidget(antiFishWidget, 7, 1); //连接信号槽 connect(testButton, &QPushButton::clicked, this, &MainWindow::onGetDetailListClicked); connect(handshakeButton, &QPushButton::clicked, this, &MainWindow::onHandshakeClicked); connect(workModeButton, &QPushButton::clicked, this, &MainWindow::onWorkModeClicked); connect(currencyButton, &QPushButton::clicked, this, &MainWindow::onCurrencyButtonClicked); connect(presetButton, &QPushButton::clicked, this, &MainWindow::onPresetButtonClicked); connect(presetAmountButton, &QPushButton::clicked, this, &MainWindow::onPresetAmountButtonClicked); connect(rejectListButton, &QPushButton::clicked, this, &MainWindow::onGetRejectListClicked); connect(detailedlistButton, &QPushButton::clicked,this,&MainWindow::onDetailedlistClicked); connect(SensorvoltageButton, &QPushButton::clicked, this, &MainWindow::onSensorvoltageClicked); connect(speedButton,&QPushButton::clicked,this,&MainWindow::onSpeedButtonClicked); connect(versionSortButton,&QPushButton::clicked,this,&MainWindow::onVersionSortButtonClicked); connect(rejectCountButton, &QPushButton::clicked, this, &MainWindow::onRejectCountButtonClicked); connect(queryCurrencyButton, &QPushButton::clicked, this, &MainWindow::onSelectCurrency); connect(ansiFishButton,&QPushButton::clicked,this,&MainWindow::onAntiFishClicked); connect(startMachineButton, &QPushButton::clicked, this, &MainWindow::onStartMachineClicked); connect(handleSelfButton, &QPushButton::clicked, this, &MainWindow::onhandleSelfClicked); return page; } QWidget* MainWindow::createSecondCommandPage() { QWidget *page = new QWidget(); QGridLayout *grid = new QGridLayout(page); grid->setSpacing(10); grid->setContentsMargins(10, 10, 10, 10); //蜂鸣器按钮 QWidget *buzzerWidget = new QWidget(); QVBoxLayout *buzzerLayout = new QVBoxLayout(buzzerWidget); buzzerLayout->setContentsMargins(0, 0, 0, 0); buzzerLayout->setSpacing(2); buzzerLabel = new QLabel("蜂鸣器"); buzzerLabel->setStyleSheet("color:#388087; font-weight: bold;"); buzzerLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); buzzerLayout->addWidget(buzzerLabel); buzzerButton = new QPushButton("设置机器蜂鸣器"); buzzerButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); buzzerButton->setStyleSheet(buttonStyle); buzzerLayout->addWidget(buzzerButton); grid->addWidget(buzzerWidget, 0, 0); //防尘罩按钮 - 无label QWidget *dustCoverWidget = new QWidget(); QVBoxLayout *dustCoverLayout = new QVBoxLayout(dustCoverWidget); dustCoverLayout->setContentsMargins(0, 0, 0, 0); dustCoverLayout->setSpacing(2); //添加一个空的占位label,保持高度一致 QLabel *emptyLabel1 = new QLabel(); emptyLabel1->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel1->setAlignment(Qt::AlignLeft | Qt::AlignBottom); dustCoverLayout->addWidget(emptyLabel1); QPushButton *openDustCoverButton = new QPushButton("打开防尘罩"); openDustCoverButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); openDustCoverButton->setStyleSheet(buttonStyle); dustCoverLayout->addWidget(openDustCoverButton); grid->addWidget(dustCoverWidget,0, 1); //底部挡板按钮 - 无label QWidget *bottomGateWidget = new QWidget(); QVBoxLayout *bottomGateLayout = new QVBoxLayout(bottomGateWidget); bottomGateLayout->setContentsMargins(0, 0, 0, 0); bottomGateLayout->setSpacing(2); QLabel *emptyLabel2 = new QLabel(); emptyLabel2->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel2->setAlignment(Qt::AlignLeft | Qt::AlignBottom); bottomGateLayout->addWidget(emptyLabel2); QPushButton *openBottomGateButton = new QPushButton("打开底部挡板"); openBottomGateButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); openBottomGateButton->setStyleSheet(buttonStyle); bottomGateLayout->addWidget(openBottomGateButton); grid->addWidget(bottomGateWidget, 1, 0); //关闭防尘罩按钮 - 无label QWidget *closeDustCoverWidget = new QWidget(); QVBoxLayout *closeDustCoverLayout = new QVBoxLayout(closeDustCoverWidget); closeDustCoverLayout->setContentsMargins(0, 0, 0, 0); closeDustCoverLayout->setSpacing(2); QLabel *emptyLabel5 = new QLabel(); emptyLabel5->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel5->setAlignment(Qt::AlignLeft | Qt::AlignBottom); closeDustCoverLayout->addWidget(emptyLabel5); QPushButton *closeDustCoverButton = new QPushButton("关闭防尘罩"); closeDustCoverButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); closeDustCoverButton->setStyleSheet(buttonStyle); closeDustCoverLayout->addWidget(closeDustCoverButton); grid->addWidget(closeDustCoverWidget, 1, 1); //关闭底部挡板按钮 - 无label QWidget *closeBottomGateWidget = new QWidget(); QVBoxLayout *closeBottomGateLayout = new QVBoxLayout(closeBottomGateWidget); closeBottomGateLayout->setContentsMargins(0, 0, 0, 0); closeBottomGateLayout->setSpacing(2); QLabel *emptyLabel6 = new QLabel(); emptyLabel6->setStyleSheet("color:#388087; font-weight: bold;"); emptyLabel6->setAlignment(Qt::AlignLeft | Qt::AlignBottom); closeBottomGateLayout->addWidget(emptyLabel6); QPushButton *closeBottomGateButton = new QPushButton("关闭底部挡板"); closeBottomGateButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); closeBottomGateButton->setStyleSheet(buttonStyle); closeBottomGateLayout->addWidget(closeBottomGateButton); grid->addWidget(closeBottomGateWidget, 2, 0); //CIS校验按钮 QWidget *cisCheckWidget = new QWidget(); QVBoxLayout *cisCheckLayout = new QVBoxLayout(cisCheckWidget); cisCheckLayout->setContentsMargins(0, 0, 0, 0); cisCheckLayout->setSpacing(2); QLabel *cisCheckLabel = new QLabel("CIS校验"); cisCheckLabel->setStyleSheet("color:#388087; font-weight: bold;"); cisCheckLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); cisCheckLayout->addWidget(cisCheckLabel); cisCheckButton = new QPushButton("CIS传感器校验"); cisCheckButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); cisCheckButton->setStyleSheet(buttonStyle); cisCheckLayout->addWidget(cisCheckButton); grid->addWidget(cisCheckWidget, 2, 1); //出厂设置 QWidget *factoryResetWidget = new QWidget(); QVBoxLayout *factoryResetLayout = new QVBoxLayout(factoryResetWidget); factoryResetLayout->setContentsMargins(0, 0, 0, 0); factoryResetLayout->setSpacing(2); QLabel *factoryResetLabel = new QLabel(); factoryResetLabel->setStyleSheet("color:#388087; font-weight: bold;"); factoryResetLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); factoryResetLayout->addWidget(factoryResetLabel); QPushButton *factoryResetButton = new QPushButton("恢复出厂设置"); factoryResetButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); factoryResetButton->setStyleSheet(buttonStyle); factoryResetLayout->addWidget(factoryResetButton); grid->addWidget(factoryResetWidget, 3, 0); //按键功能按钮 QWidget *pressWidget = new QWidget(); QVBoxLayout *pressLayout = new QVBoxLayout(pressWidget); pressLayout->setContentsMargins(0, 0, 0, 0); pressLayout->setSpacing(2); QLabel *pressLabel = new QLabel("按键功能"); pressLabel->setStyleSheet("color:#388087; font-weight: bold;"); pressLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); pressLayout->addWidget(pressLabel); pressButton = new QPushButton("按键功能"); pressButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); pressButton->setStyleSheet(buttonStyle); pressLayout->addWidget(pressButton); grid->addWidget(pressWidget, 3, 1); //老化命令 QWidget *agingWidget = new QWidget(); QVBoxLayout *agingLayout = new QVBoxLayout(agingWidget); agingLayout->setContentsMargins(0, 0, 0, 0); agingLayout->setSpacing(2); QLabel *agingLabel = new QLabel("老化"); agingLabel->setStyleSheet("color:#388087; font-weight: bold;"); agingLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); agingLayout->addWidget(agingLabel); agingButton = new QPushButton("准备老化"); agingButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); agingButton->setStyleSheet(buttonStyle); agingLayout->addWidget(agingButton); grid->addWidget(agingWidget, 4, 0); grid->setRowStretch(5, 1); //让第5行(索引4)占据剩余空间 //连接信号槽 connect(cisCheckButton, &QPushButton::clicked, this, [this](){ if(!m_serialWorker) { logMessage("串口未打开"); return; } setButtonActive(qobject_cast<QPushButton*>(sender())); sendCISCheckCommand(); }); connect(pressButton,&QPushButton::clicked,this,&MainWindow::onPressButtonClicked); connect(openDustCoverButton, &QPushButton::clicked, this, &MainWindow::onOpenDustCoverClicked); connect(openBottomGateButton, &QPushButton::clicked, this, &MainWindow::onOpenBottomGateClicked); connect(closeDustCoverButton, &QPushButton::clicked, this, &MainWindow::onCloseDustCoverClicked); connect(closeBottomGateButton, &QPushButton::clicked, this, &MainWindow::onCloseBottomGateClicked); connect(buzzerButton, &QPushButton::clicked, this, &MainWindow::onSetBuzzerClicked); connect(factoryResetButton, &QPushButton::clicked, this, &MainWindow::onFactoryResetClicked); connect(agingButton, &QPushButton::clicked, this, &MainWindow::onAgingClicked); return page; } #include "serialworker.h" #include <QDebug> #include <QSerialPortInfo> SerialWorker::SerialWorker(const QString &portName, qint32 baudRate, QObject *parent) : QThread(parent), m_portName(portName), m_serialPort(nullptr), m_running(false), m_baudRate(baudRate) { } SerialWorker::~SerialWorker() { stop(); } //设置波特率 void SerialWorker::setBaudRate(qint32 baudRate) { m_baudRate = baudRate; if(m_serialPort && m_serialPort->isOpen()) { m_serialPort->setBaudRate(m_baudRate); } } void SerialWorker::run() { // 检查串口是否已存在 bool portAvailable = false; const auto ports = QSerialPortInfo::availablePorts(); for(const QSerialPortInfo &port : ports) { if(port.portName() == m_portName) { portAvailable = true; break; } } if(!portAvailable) { emit errorOccurred(tr("串口 %1 不存在").arg(m_portName)); return; } m_serialPort = new QSerialPort(); m_serialPort->setPortName(m_portName); m_serialPort->setBaudRate(m_baudRate); //成员变量设置波特率 m_serialPort->setDataBits(QSerialPort::Data8); m_serialPort->setParity(QSerialPort::NoParity); m_serialPort->setStopBits(QSerialPort::OneStop); m_serialPort->setFlowControl(QSerialPort::NoFlowControl); if(!m_serialPort->open(QIODevice::ReadWrite)) { emit errorOccurred(tr("无法打开串口 %1: %2").arg(m_portName).arg(m_serialPort->errorString())); delete m_serialPort; m_serialPort = nullptr; return; } m_running = true; //读取串口数据 while(m_running) { if(m_serialPort->waitForReadyRead(100)) { //等待数据到达 QByteArray data = m_serialPort->readAll(); //读取可用数据 //尝试读取剩余数据 while(m_serialPort->waitForReadyRead(10)) { data += m_serialPort->readAll(); } emit dataReceived(data); //发送接收到的数据 } //检查串口是否仍然打开 if(!m_serialPort->isOpen()) { emit errorOccurred(tr("串口 %1 意外关闭").arg(m_portName)); break; } } //清理串口对象 if(m_serialPort) { m_serialPort->close(); delete m_serialPort; m_serialPort = nullptr; } } void SerialWorker::stop() { m_running = false; wait(); } void SerialWorker::send(const QByteArray &data) { //发送数据到串口 if(m_serialPort && m_serialPort->isOpen()) { if(m_serialPort->write(data) == -1) { emit errorOccurred(tr("发送数据失败: %1").arg(m_serialPort->errorString())); } } } 这个能否增加一个识别数据线是否断开呢,如果数据线断开我的PC就主动断开串口,并且在断开串口前在logMessage显示数据线已断开

最新推荐

recommend-type

C# Socket通信源码:多连接支持与断线重连功能的物联网解决方案

内容概要:本文介绍了一套基于C#编写的Socket服务器与客户端通信源码,源自商业级物联网项目。这套代码实现了双Socket机制、多连接支持以及断线重连功能,适用于各类C#项目(如MVC、Winform、控制台、Webform)。它通过简单的静态类调用即可获取客户端传输的数据,并内置了接收和发送数据缓冲队列,确保数据传输的稳定性。此外,代码提供了数据读取接口,但不涉及具体的数据处理逻辑。文中详细展示了服务端和客户端的基本配置与使用方法,强调了在实际应用中需要注意的问题,如避免主线程执行耗时操作以防内存膨胀。 适合人群:具备基本C#编程能力的研发人员,尤其是对Socket通信有一定了解并希望快速集成相关功能到现有项目中的开发者。 使用场景及目标:① 需要在短时间内为C#项目增加稳定的Socket通信功能;② 实现多设备间的数据交换,特别是对于智能家居、工业传感器等物联网应用场景。 其他说明:虽然该代码能够满足大多数中小型项目的通信需求,但对于需要高性能、低延迟的金融级交易系统则不太合适。同时,代码并未采用异步技术,因此在面对海量连接时可能需要进一步优化。
recommend-type

掌握XFireSpring整合技术:HELLOworld原代码使用教程

标题:“xfirespring整合使用原代码”中提到的“xfirespring”是指将XFire和Spring框架进行整合使用。XFire是一个基于SOAP的Web服务框架,而Spring是一个轻量级的Java/Java EE全功能栈的应用程序框架。在Web服务开发中,将XFire与Spring整合能够发挥两者的优势,例如Spring的依赖注入、事务管理等特性,与XFire的简洁的Web服务开发模型相结合。 描述:“xfirespring整合使用HELLOworld原代码”说明了在这个整合过程中实现了一个非常基本的Web服务示例,即“HELLOworld”。这通常意味着创建了一个能够返回"HELLO world"字符串作为响应的Web服务方法。这个简单的例子用来展示如何设置环境、编写服务类、定义Web服务接口以及部署和测试整合后的应用程序。 标签:“xfirespring”表明文档、代码示例或者讨论集中于XFire和Spring的整合技术。 文件列表中的“index.jsp”通常是一个Web应用程序的入口点,它可能用于提供一个用户界面,通过这个界面调用Web服务或者展示Web服务的调用结果。“WEB-INF”是Java Web应用中的一个特殊目录,它存放了应用服务器加载的Servlet类文件和相关的配置文件,例如web.xml。web.xml文件中定义了Web应用程序的配置信息,如Servlet映射、初始化参数、安全约束等。“META-INF”目录包含了元数据信息,这些信息通常由部署工具使用,用于描述应用的元数据,如manifest文件,它记录了归档文件中的包信息以及相关的依赖关系。 整合XFire和Spring框架,具体知识点可以分为以下几个部分: 1. XFire框架概述 XFire是一个开源的Web服务框架,它是基于SOAP协议的,提供了一种简化的方式来创建、部署和调用Web服务。XFire支持多种数据绑定,包括XML、JSON和Java数据对象等。开发人员可以使用注解或者基于XML的配置来定义服务接口和服务实现。 2. Spring框架概述 Spring是一个全面的企业应用开发框架,它提供了丰富的功能,包括但不限于依赖注入、面向切面编程(AOP)、数据访问/集成、消息传递、事务管理等。Spring的核心特性是依赖注入,通过依赖注入能够将应用程序的组件解耦合,从而提高应用程序的灵活性和可测试性。 3. XFire和Spring整合的目的 整合这两个框架的目的是为了利用各自的优势。XFire可以用来创建Web服务,而Spring可以管理这些Web服务的生命周期,提供企业级服务,如事务管理、安全性、数据访问等。整合后,开发者可以享受Spring的依赖注入、事务管理等企业级功能,同时利用XFire的简洁的Web服务开发模型。 4. XFire与Spring整合的基本步骤 整合的基本步骤可能包括添加必要的依赖到项目中,配置Spring的applicationContext.xml,以包括XFire特定的bean配置。比如,需要配置XFire的ServiceExporter和ServicePublisher beans,使得Spring可以管理XFire的Web服务。同时,需要定义服务接口以及服务实现类,并通过注解或者XML配置将其关联起来。 5. Web服务实现示例:“HELLOworld” 实现一个Web服务通常涉及到定义服务接口和服务实现类。服务接口定义了服务的方法,而服务实现类则提供了这些方法的具体实现。在XFire和Spring整合的上下文中,“HELLOworld”示例可能包含一个接口定义,比如`HelloWorldService`,和一个实现类`HelloWorldServiceImpl`,该类有一个`sayHello`方法返回"HELLO world"字符串。 6. 部署和测试 部署Web服务时,需要将应用程序打包成WAR文件,并部署到支持Servlet 2.3及以上版本的Web应用服务器上。部署后,可以通过客户端或浏览器测试Web服务的功能,例如通过访问XFire提供的服务描述页面(WSDL)来了解如何调用服务。 7. JSP与Web服务交互 如果在应用程序中使用了JSP页面,那么JSP可以用来作为用户与Web服务交互的界面。例如,JSP可以包含JavaScript代码来发送异步的AJAX请求到Web服务,并展示返回的结果给用户。在这个过程中,JSP页面可能使用XMLHttpRequest对象或者现代的Fetch API与Web服务进行通信。 8. 项目配置文件说明 项目配置文件如web.xml和applicationContext.xml分别在Web应用和服务配置中扮演关键角色。web.xml负责定义Web组件,比如Servlet、过滤器和监听器,而applicationContext.xml则负责定义Spring容器中的bean,包括数据源、事务管理器、业务逻辑组件和服务访问器等。 总之,通过上述整合使用原代码的知识点,可以深入理解XFire与Spring框架的结合使用,以及如何开发和部署基本的Web服务。这些技术知识有助于进行更高层次的Web服务开发,以及在复杂的IT环境中灵活运用各种框架和工具。
recommend-type

【Unity2018汉化大揭秘】:一步到位优化中文用户体验

# 摘要 本论文详细介绍了Unity2018汉化项目的实施过程,从理论准备到实践步骤,再到后期的测试与优化,最终分享了汉化经验和心得。首先,强调了汉化项目对于用户体验提升和产品国际化的重要性,并分析了汉化资源的分类、识别与管理方法。接着,详细阐述了汉化工具的选择、脚本编写、资源手动调整等实践步骤,以及汉化质量测试、体验优化和项目维护更新的重要性。论文最后通过案例研究,分析了汉化中的挑战和应对策略,并预测了汉化技术未来的发展方向。整个汉化过程不仅涉及技术层面的操作,还包含了深入的理论研究和实践心得分享,对提升汉化项目的效率和质量具有指导意义。 # 关键字 Unity汉化;用户体验;国际化;资源
recommend-type

iPhone

<think>我们注意到用户意图不明确,但提到了“照片提取”和“其他功能帮助”。因此,我们需要通过搜索来获取关于iPhone照片提取的常见方法以及其他可能的功能帮助。由于用户问题比较宽泛,我们将重点放在照片提取上,因为这是明确提到的关键词。同时,我们也会考虑一些其他常用功能的帮助。首先,针对照片提取,可能涉及从iPhone导出照片、从备份中提取照片、或者从损坏的设备中恢复照片等。我们将搜索这些方面的信息。其次,关于其他功能帮助,我们可以提供一些常见问题的快速指南,如电池优化、屏幕时间管理等。根据要求,我们需要将答案组织为多个方法或步骤,并在每个步骤间换行。同时,避免使用第一人称和步骤词汇。由于
recommend-type

驾校一点通软件:提升驾驶证考试通过率

标题“驾校一点通”指向的是一款专门为学员考取驾驶证提供帮助的软件,该软件强调其辅助性质,旨在为学员提供便捷的学习方式和复习资料。从描述中可以推断出,“驾校一点通”是一个与驾驶考试相关的应用软件,这类软件一般包含驾驶理论学习、模拟考试、交通法规解释等内容。 文件标题中的“2007”这个年份标签很可能意味着软件的最初发布时间或版本更新年份,这说明了软件具有一定的历史背景和可能经过了多次更新,以适应不断变化的驾驶考试要求。 压缩包子文件的文件名称列表中,有以下几个文件类型值得关注: 1. images.dat:这个文件名表明,这是一个包含图像数据的文件,很可能包含了用于软件界面展示的图片,如各种标志、道路场景等图形。在驾照学习软件中,这类图片通常用于帮助用户认识和记忆不同交通标志、信号灯以及驾驶过程中需要注意的各种道路情况。 2. library.dat:这个文件名暗示它是一个包含了大量信息的库文件,可能包含了法规、驾驶知识、考试题库等数据。这类文件是提供给用户学习驾驶理论知识和准备科目一理论考试的重要资源。 3. 驾校一点通小型汽车专用.exe:这是一个可执行文件,是软件的主要安装程序。根据标题推测,这款软件主要是针对小型汽车驾照考试的学员设计的。通常,小型汽车(C1类驾照)需要学习包括车辆构造、基础驾驶技能、安全行车常识、交通法规等内容。 4. 使用说明.html:这个文件是软件使用说明的文档,通常以网页格式存在,用户可以通过浏览器阅读。使用说明应该会详细介绍软件的安装流程、功能介绍、如何使用软件的各种模块以及如何通过软件来帮助自己更好地准备考试。 综合以上信息,我们可以挖掘出以下几个相关知识点: - 软件类型:辅助学习软件,专门针对驾驶考试设计。 - 应用领域:主要用于帮助驾考学员准备理论和实践考试。 - 文件类型:包括图片文件(images.dat)、库文件(library.dat)、可执行文件(.exe)和网页格式的说明文件(.html)。 - 功能内容:可能包含交通法规知识学习、交通标志识别、驾驶理论学习、模拟考试、考试题库练习等功能。 - 版本信息:软件很可能最早发布于2007年,后续可能有多个版本更新。 - 用户群体:主要面向小型汽车驾照考生,即C1类驾照学员。 - 使用方式:用户需要将.exe安装文件进行安装,然后根据.html格式的使用说明来熟悉软件操作,从而利用images.dat和library.dat中的资源来辅助学习。 以上知识点为从给定文件信息中提炼出来的重点,这些内容对于了解“驾校一点通”这款软件的功能、作用、使用方法以及它的发展历史都有重要的指导意义。
recommend-type

【DFLauncher自动化教程】:简化游戏启动流程,让游戏体验更流畅

# 摘要 DFLauncher是一个功能丰富的游戏启动和管理平台,本论文将介绍其安装、基础使用、高级设置、社区互动以及插件开发等方面。通过对配置文件的解析、界面定制、自动化功能的实现、高级配置选项、安全性和性能监控的详细讨论,本文阐述了DFLauncher如何帮助用户更高效地管理和优化游戏环境。此外,本文还探讨了DFLauncher社区的资源分享、教育教程和插件开发等内容,
recommend-type

自适应卡尔曼滤波是什么意思

<think>嗯,用户这次想深入了解自适应卡尔曼滤波(AKF)的概念和原理。从对话历史看,用户之前研究过相机自动对焦系统的降噪技术,其中提到过自适应卡尔曼滤波的应用场景。用户可能是个工程师或研究者,正在探索信号处理在具体场景的实现细节。 用户提供的三篇参考文献很有价值:[1]是基础理论综述,[2]聚焦多传感器场景,[3]讨论噪声协方差自适应方法。需要特别注意相机AF系统的特殊需求——实时性要求高(每秒数十次对焦计算)、噪声环境复杂(机械振动/弱光干扰),这些在解释原理时要结合具体案例。 技术要点需要分层解析:先明确标准卡尔曼滤波的局限(固定噪声参数),再展开自适应机制。对于相机AF场景,重
recommend-type

EIA-CEA 861B标准深入解析:时间与EDID技术

EIA-CEA 861B标准是美国电子工业联盟(Electronic Industries Alliance, EIA)和消费电子协会(Consumer Electronics Association, CEA)联合制定的一个技术规范,该规范详细规定了视频显示设备和系统之间的通信协议,特别是关于视频显示设备的时间信息(timing)和扩展显示识别数据(Extended Display Identification Data,简称EDID)的结构与内容。 在视频显示技术领域,确保不同品牌、不同型号的显示设备之间能够正确交换信息是至关重要的,而这正是EIA-CEA 861B标准所解决的问题。它为制造商提供了一个统一的标准,以便设备能够互相识别和兼容。该标准对于确保设备能够正确配置分辨率、刷新率等参数至关重要。 ### 知识点详解 #### EIA-CEA 861B标准的历史和重要性 EIA-CEA 861B标准是随着数字视频接口(Digital Visual Interface,DVI)和后来的高带宽数字内容保护(High-bandwidth Digital Content Protection,HDCP)等技术的发展而出现的。该标准之所以重要,是因为它定义了电视、显示器和其他显示设备之间如何交互时间参数和显示能力信息。这有助于避免兼容性问题,并确保消费者能有较好的体验。 #### Timing信息 Timing信息指的是关于视频信号时序的信息,包括分辨率、水平频率、垂直频率、像素时钟频率等。这些参数决定了视频信号的同步性和刷新率。正确配置这些参数对于视频播放的稳定性和清晰度至关重要。EIA-CEA 861B标准规定了多种推荐的视频模式(如VESA标准模式)和特定的时序信息格式,使得设备制造商可以参照这些标准来设计产品。 #### EDID EDID是显示设备向计算机或其他视频源发送的数据结构,包含了关于显示设备能力的信息,如制造商、型号、支持的分辨率列表、支持的视频格式、屏幕尺寸等。这种信息交流机制允许视频源设备能够“了解”连接的显示设备,并自动设置最佳的输出分辨率和刷新率,实现即插即用(plug and play)功能。 EDID的结构包含了一系列的块(block),其中定义了包括基本显示参数、色彩特性、名称和序列号等在内的信息。该标准确保了这些信息能以一种标准的方式被传输和解释,从而简化了显示设置的过程。 #### EIA-CEA 861B标准的应用 EIA-CEA 861B标准不仅适用于DVI接口,还适用于HDMI(High-Definition Multimedia Interface)和DisplayPort等数字视频接口。这些接口技术都必须遵循EDID的通信协议,以保证设备间正确交换信息。由于标准的广泛采用,它已经成为现代视频信号传输和显示设备设计的基础。 #### EIA-CEA 861B标准的更新 随着技术的进步,EIA-CEA 861B标准也在不断地更新和修订。例如,随着4K分辨率和更高刷新率的显示技术的发展,该标准已经扩展以包括支持这些新技术的时序和EDID信息。任何显示设备制造商在设计新产品时,都必须考虑最新的EIA-CEA 861B标准,以确保兼容性。 #### 结论 EIA-CEA 861B标准是电子显示领域的一个重要规范,它详细定义了视频显示设备在通信时所使用的信号时序和设备信息的格式。该标准的存在,使得不同厂商生产的显示设备可以无缝连接和集成,极大地增强了用户体验。对于IT专业人士而言,了解和遵守EIA-CEA 861B标准是进行视频系统设计、故障诊断及设备兼容性测试的重要基础。
recommend-type

【DFLauncher应用实战】:如何将DFLauncher融入矮人要塞并提升效率

# 摘要 DFLauncher是一款功能全面的游戏管理工具,旨在简化游戏安装、启动和维护过程。本文介绍了DFLauncher的基本使用方法,详细解析了其核心功能,包括游戏库管理、游戏配置优化、更新机制等。同时,文章探讨了DFLauncher在特定游戏“矮人要塞”中的集成应用,以及通过插件和脚本进行的高级定制。故障诊断与系统优化章节提供了实用的诊断方法和性能提升技巧。最后,本文展望了DFLauncher的未来发展方向,并鼓励社区贡献和用户反馈,以满足不断变化的用户需求。 # 关键字 DFLauncher;游戏管理工具;安装配置;性能优化;故障诊断;社区贡献;定制化扩展;网络功能集成 参考资源
recommend-type

银河麒麟系统打开屏保

<think>嗯,用户的问题是关于银河麒麟操作系统如何开启屏幕保护程序。这个问题其实挺实用的,毕竟长时间盯着电脑屏幕容易造成视觉疲劳,屏幕保护能起到一定的保护作用。 从用户提供的引用内容来看,引用[2]提到了银河麒麟系统的常见问题处理,包括重启输入法和双屏配置问题,虽然不直接相关,但说明用户对系统设置有一定了解。引用[3]是关于安装cmake的,可能用户之前尝试过其他系统配置操作。 用户可能是在办公环境中使用银河麒麟系统,需要保护视力。考虑到银河麒麟是基于Linux开发的国产操作系统,它的屏幕保护设置应该和主流Linux发行版类似,但可能有自己的特色功能。 我回忆了一下Linux系统的屏