2024-05-28 10:41:18 +08:00
|
|
|
#include <qwidget.h>
|
|
|
|
|
#include <qlabel.h>
|
|
|
|
|
#include <qcombobox.h>
|
|
|
|
|
#include <qlayout.h>
|
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
|
class switchProductWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-05-28 10:46:04 +08:00
|
|
|
QLabel* staticLabel = new QLabel(this);
|
|
|
|
|
|
2024-05-28 10:41:18 +08:00
|
|
|
int currentProductIndex = 0;
|
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
|
fancyButtonText* switchBtn = new fancyButtonText(100, 60, "修改", "修改当前机型");
|
|
|
|
|
QComboBox* productSelect = new QComboBox(this);
|
|
|
|
|
QLabel* currentProduct = new QLabel(this);
|
|
|
|
|
switchProductWidget()
|
|
|
|
|
{
|
2024-05-28 10:46:04 +08:00
|
|
|
QPalette palette;
|
|
|
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
|
QFont font("微软雅黑", 14, QFont::Bold);
|
2024-05-28 10:41:18 +08:00
|
|
|
this->setLayout(layout);
|
|
|
|
|
|
2024-05-28 10:46:04 +08:00
|
|
|
staticLabel->setText("当前型号:");
|
|
|
|
|
staticLabel->setFont(font);
|
|
|
|
|
staticLabel->setPalette(palette);
|
|
|
|
|
layout->addWidget(staticLabel);
|
|
|
|
|
|
2024-05-28 10:41:18 +08:00
|
|
|
productSelect->addItem("产品1");
|
|
|
|
|
productSelect->addItem("产品2");
|
2024-05-28 10:46:04 +08:00
|
|
|
productSelect->setPalette(palette);
|
|
|
|
|
productSelect->setFont(font);
|
2024-05-28 10:41:18 +08:00
|
|
|
|
|
|
|
|
layout->addWidget(productSelect);
|
|
|
|
|
productSelect->hide();
|
|
|
|
|
|
|
|
|
|
currentProduct->setText("产品1");
|
2024-05-28 10:46:04 +08:00
|
|
|
currentProduct->setFont(font);
|
|
|
|
|
currentProduct->setPalette(palette);
|
|
|
|
|
|
2024-05-28 10:41:18 +08:00
|
|
|
layout->addWidget(currentProduct);
|
|
|
|
|
layout->addWidget(switchBtn);
|
|
|
|
|
|
|
|
|
|
connect(switchBtn, &QPushButton::clicked, this, &switchProductWidget::startSwitch);
|
|
|
|
|
connect(productSelect, &QComboBox::currentTextChanged, this, &switchProductWidget::currentProductSwitch);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
int siwtchBtnState = 0;
|
|
|
|
|
private slots:
|
|
|
|
|
void startSwitch()
|
|
|
|
|
{
|
|
|
|
|
if(siwtchBtnState == 0)
|
|
|
|
|
{
|
|
|
|
|
currentProduct->hide();
|
|
|
|
|
productSelect->show();
|
|
|
|
|
switchBtn->setText("取消");
|
|
|
|
|
siwtchBtnState = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (siwtchBtnState == 1)
|
|
|
|
|
{
|
|
|
|
|
currentProduct->show();
|
|
|
|
|
productSelect->hide();
|
|
|
|
|
switchBtn->setText("修改");
|
|
|
|
|
siwtchBtnState = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void currentProductSwitch(QString input)
|
|
|
|
|
{
|
|
|
|
|
int index = productSelect->currentIndex();
|
2024-05-28 10:46:04 +08:00
|
|
|
|
|
|
|
|
currentProduct->setText(input);
|
|
|
|
|
|
|
|
|
|
startSwitch();
|
2024-05-28 10:41:18 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma once
|