您的位置:首页 > 编程语言 > Qt开发

QT学习笔记_布局

2014-09-26 18:48 281 查看
布局大致分水平布局,竖直布局 ,网格布局等等。。

#include <QApplication>
#include <QHBoxLayout>//布局
#include <QSlider>//滑块
#include <QSpinBox>//微调框
#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();
}
效果图:




唯一美中不足的是 还是窗口太小。。百度一下了这个问题,发现资料少的可伶。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: