QT5笔记: 14. SpinBox的常用功能
- 例子:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->spinBoxNumber, SIGNAL(valueChanged(int)), this, SLOT(on_spinBox_valueChanged(int)));
connect(ui->doubleSpinBoxPrice, SIGNAL(valueChanged(double)), this, SLOT(on_spinBoxDouble_valueChanged(double)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_spinBox_valueChanged(int arg1)
{
double price = ui->doubleSpinBoxPrice->value();
double total = arg1 * price;
ui->doubleSpinBoxTotal->setValue(total);
}
void Widget::on_spinBoxDouble_valueChanged(double arg1)
{
int number = ui->spinBoxNumber->value();
double total = number * arg1;
ui->doubleSpinBoxTotal->setValue(total);
}
/**
* @brief Widget::on_btnConvert_clicked
* @note SpinBox有属性,来显示进制,当设置十进制的数,他会对应转换为要显示的进制,但是他的value值是十进制数
*/
void Widget::on_btnConvert_clicked()
{
int dec = ui->spinBoxDec->value();
ui->spinBoxBin->setValue(dec);
ui->spinBoxHex->setValue(dec);
}
void Widget::on_btnConvertBin_clicked()
{
int bin = ui->spinBoxBin->value();
ui->spinBoxDec->setValue(bin);
ui->spinBoxHex->setValue(bin);
}
void Widget::on_btnConvertHex_clicked()
{
int hex = ui->spinBoxHex->value();
ui->spinBoxBin->setValue(hex);
ui->spinBoxDec->setValue(hex);
}
-
界面: