QT 实现SpinBox与Slider相互控制

#include
#include
#include
#include
#include
int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
    QWidget* pWin = new QWidget;
    pWin->setWindowTitle("输入你的年龄:");
    QSpinBox* pSpin = new QSpinBox;
    QSlider* pSlider = new QSlider(Qt::Horizontal);
    pSpin->setRange(0, 130);
    pSlider->setRange(0, 130);
    QObject::connect(pSpin, SIGNAL(valueChanged(int)), pSlider, SLOT(setValue(int)));
    QObject::connect(pSlider, SIGNAL(valueChanged(int)), pSpin, SLOT(setValue(int)));
    pSpin->setValue(35);
    QHBoxLayout* pLayOut = new QHBoxLayout;
    pLayOut->addWidget(pSpin);
    pLayOut->addWidget(pSlider);
    pWin->setLayout(pLayOut);
    pWin->show();
 
  
    return app.exec();
}

你可能感兴趣的:(QT)