qt滚动条与调整框联动

#include "mainwindow.h"
#include <QApplication>
#include<QSlider>
#include<QSpinBox>
#include<QWidget>
#include<QLayout>
int main(int argc, char *argv[])
{
  
  
    QApplication a(argc, argv);
 
 
    QWidget *wiget = new QWidget;
    wiget->setWindowTitle("Layout Test");
 
 
    QSpinBox *spin =new QSpinBox;
    QSlider *slider =new QSlider;
    spin->setRange(0,100);
    slider->setRange(0,100);
 
 
    QObject::connect(spin,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    QObject::connect(slider,SIGNAL(valueChanged(int)),spin,SLOT(setValue(int)));
    spin->setValue(10);
 
 
    QHBoxLayout *layout=new QHBoxLayout;
    layout->addWidget(spin);
    layout->addWidget(slider);
 
 
    wiget->setLayout(layout);
    wiget->show();
 
 
    return a.exec();
}
 

猜你喜欢

转载自blog.csdn.net/wyyy2088511/article/details/127194386