#include "frmdevice.h" #include "ui_frmdevice.h" #include "quihelper.h" #include "frmdevicepanel.h" #include "frmdevicepanelx.h" #define frmdevicepanel frmDevice::frmDevice(QWidget *parent) : QWidget(parent), ui(new Ui::frmDevice) { ui->setupUi(this); this->initForm(); QTimer::singleShot(100, this, SLOT(initPanel())); } frmDevice::~frmDevice() { delete ui; } bool frmDevice::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { QString objName = watched->objectName(); if (objName.startsWith("frmDevicePanel")) { int index = objName.right(1).toInt(); //将当前按下的窗体高亮 for (int i = 0; i < frms.count(); i++) { #ifdef frmdevicepanel frmDevicePanel *frm = (frmDevicePanel *)frms.at(i); #else frmDevicePanelX *frm = (frmDevicePanelX *)frms.at(i); #endif frm->setChecked(i == index); } } } return QWidget::eventFilter(watched, event); } void frmDevice::initForm() { } void frmDevice::initPanel() { qDeleteAll(frms); frms.clear(); QStringList names; names << "通道A1" << "通道B1" << "通道C1" << "通道A2" << "通道B2" << "通道C2"; for (int i = 0; i < 6; i++) { #ifdef frmdevicepanel frmDevicePanel *frm = new frmDevicePanel; #else frmDevicePanelX *frm = new frmDevicePanelX; #endif frm->setObjectName("frmDevicePanel" + QString::number(i)); frm->installEventFilter(this); connect(this, SIGNAL(changeStyle(QString)), frm, SLOT(changeStyle(QString))); frm->setName(names.at(i)); frms.append(frm); } ui->widgetPanel->setAutoHeight(true); ui->widgetPanel->setAutoWidth(true); ui->widgetPanel->setMargin(6); ui->widgetPanel->setSpace(6); ui->widgetPanel->setColumnCount(3); ui->widgetPanel->setWidgets(frms); }