- 论坛徽章:
- 0
|
//On a widget build a QSlider and QSpinBox,connect the QSpinBox valueChanged(int) singal to QSlider setValue(int) slot,as well as
//connect the QSlider valueChanged(int) signal to QSpinBox setValue(int) slot
#include
#include
#include
#include
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QWidget *window=new QWidget;
window->setWindowTitle("Enter your age");
QSpinBox *spinbox=new QSpinBox;
QSlider *slider=new QSlider(Qt::Horizontal);
spinbox->setRange(0,130);
slider->setRange(0,130);
QObject::connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));
spinbox->setValue(20);
QVBoxLayout *layout=new QVBoxLayout;
layout->addWidget(spinbox);
layout->addWidget(slider);
window->setLayout(layout);
window->show();
return app.exec();
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/56374/showart_518845.html |
|