QT5-控件-QSpinBox和QDoubleSpinBox(用於通過控件調整整數和小數),qt5--qspinbox
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSpinBox>
#include <QDoubleSpinBox>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QSpinBox* spin[10];
QDoubleSpinBox* doublespin[10];
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->resize(400,300);
this->centralWidget();
int xpos = 10 ;
int ypos = 30 ;
int val[] = {50,100,200};
double double_val[] = {50.5,127.32,171.342};
for(int i=0;i<3;i++)
{
spin[i] = new QSpinBox(this);
spin[i]->setMinimum(10);
spin[i]->setMaximum(300);
spin[i]->setValue(val[i]);
spin[i]->setGeometry(xpos,ypos,100,30);
spin[i]->setPrefix("$ ");
doublespin[i] = new QDoubleSpinBox(this);
doublespin[i]->setMinimum(10.0);
doublespin[i]->setMaximum(300.0);
doublespin[i]->setValue(double_val[i]);
doublespin[i]->setGeometry(xpos+110,ypos,100,30);
doublespin[i]->setSuffix(" mm");
ypos += 40 ;
}
}
MainWindow::~MainWindow()
{
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}