QT學習筆記_布局
來源:程序員人生 發(fā)布時間:2014-09-29 22:46:53 閱讀次數(shù):2531次
布局大致分水平布局,豎直布局 ,網(wǎng)格布局等等。。
#include <QApplication>
#include <QHBoxLayout>//布局
#include <QSlider>//滑塊
#include <QSpinBox>//微調(diào)框
#include <QLabel>//標簽
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QWidget *w=new QWidget;
w->setWindowTitle("enter your age");
QSpinBox *box=new QSpinBox;
QSlider *slider=new QSlider(Qt::Horizontal);
box->setRange(0,100);
slider->setRange(0,100);
//連接同步
QObject::connect(box,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),box,SLOT(setValue(int)));
box->setValue(66);
//設置布局(水平)
QHBoxLayout *layout=new QHBoxLayout();
layout->addWidget(box);
layout->addWidget(slider);
w->setLayout(layout);
w->show();
return app.exec();
}
效果圖:

唯一美中不足的是 還是窗口太小。。百度一下了這個問題,發(fā)現(xiàn)資料少的可伶。。
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈