#include "JReLineEdit.h" #include #include #include #include JReLineEdit::JReLineEdit(QWidget* parent /*= nullptr*/) : QLineEdit(parent) { } void JReLineEdit::upDataValLine(const ST_DEF_VAL _val) { m_stSavedefVal = _val; } void JReLineEdit::CheckVal() { // 获取按钮所在的父窗口 QWidget* parentWindow = this->window(); QList pListBox = parentWindow->findChildren(); QList pListQComboBox = parentWindow->findChildren(); // 遍历所有QLineEdit foreach(QGroupBox * p, pListBox) { if (p->objectName() == "axisGroupBox") { // 获取所有子控件 QList children = p->findChildren(); std::vector vecPos; int nNum = 0; // 总共没几个 ns_module::MODULE_COORD_MOVE axisPos = {}; foreach(QWidget * child, children) { if (child->metaObject()->className() == "QCheckBox") { QCheckBox* checkBox = qobject_cast(child); if (checkBox) { // 转换成功,可以安全使用 checkBox if (checkBox->isChecked()) { nNum += 1; if (checkBox->objectName() == "forceCheckBox") { } else if (checkBox->objectName() == "forceCheckBox") { } else if (checkBox->objectName() == "forceCheckBox") { } else if (checkBox->objectName() == "forceCheckBox") { } break; } } else { // 转换失败,widget 不是 QCheckBox 类型 //qDebug() << "该 widget 不是 QCheckBox"; } } // 表示是另一个控件 if (nNum == 1) { QCheckBox* checkBox = qobject_cast(child); axisPos.pos = checkBox->text().toDouble(); vecPos.push_back(axisPos); nNum = 0; } //qDebug() << "name :" << child->objectName() // << " type::" << child->metaObject()->className(); } break; } } // 获取选中 foreach(QComboBox* p, pListQComboBox) { if (p->objectName() == "modeComboBox") { m_stSavedefVal.strMode = p->currentText(); } } CreateSpeedAdjPage(); } void JReLineEdit::CreateSpeedAdjPage() { if (m_pSpeedWnd) { m_pSpeedWnd->close(); m_pSpeedWnd->deleteLater(); } m_pSpeedWnd = new SpeedAdjPage(this); m_pSpeedWnd->updateDefVal(m_stSavedefVal); m_pSpeedWnd->setAttribute(Qt::WA_DeleteOnClose); { QPoint mousePos = QCursor::pos(); QPoint newPos = QPoint(mousePos.x() - m_pSpeedWnd->width() / 2, mousePos.y() - m_pSpeedWnd->height() - 10); m_pSpeedWnd->move(newPos); } connect(m_pSpeedWnd, &SpeedAdjPage::CloseWnd, this, &JReLineEdit::GetCloseWndSlots); m_pSpeedWnd->show(); } void JReLineEdit::GetCloseWndSlots(int nVal) { double doVal = text().toDouble(); doVal = doVal + nVal; setText(QString::number(doVal, 'f', 2)); } void JReLineEdit::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) { CheckVal(); } QLineEdit::mousePressEvent(event); }