实现目的
使用QSpinBox、QDoubleSpinBox 实现数量*单价,float结果显示
使用QSpinBox、QDoubleSpinBox 实现进制的转换
拟实现界面
布局
垂直布局、groupBox中为栅格布局
控件进制设置属性 displayIntegerBase
16代表16进制
#include "spinboxexample.h"
#include "ui_spinboxexample.h"
SpinBoxExample::SpinBoxExample(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SpinBoxExample)
{
ui->setupUi(this);
}
SpinBoxExample::~SpinBoxExample()
{
delete ui;
}
void SpinBoxExample::on_btnCalc_clicked()
{
int num = ui->spinNum->value();
float price =ui->spinPrice->value();
float total = num *price;
ui->spinTotal->setValue(total);
}
void SpinBoxExample::on_spinNum_valueChanged(int arg1)
{
int num = arg1;
float price =ui->spinPrice->value();
float total = num* price;
ui->spinTotal->setValue(total);
}
void SpinBoxExample::on_spinPrice_valueChanged(double arg1)
{
int num = ui->spinNum->value();
float total = num *arg1;
ui->spinTotal->setValue(total);
}
void SpinBoxExample::on_spinDec_valueChanged(int arg1)
{
ui->spinBin->setValue(arg1);
ui->spinHex->setValue(arg1);
}
void SpinBoxExample::on_spinBin_valueChanged(int arg1)
{
ui->spinDec->setValue(arg1); //界面已经设置了 进制显示
ui->spinHex->setValue(arg1);
}
void SpinBoxExample::on_spinHex_valueChanged(int arg1)
{
ui->spinDec->setValue(arg1);
ui->spinBin->setValue(arg1);
}
SpinBox
value()读取value值;setValue(value)设置值
结果