Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1974487
  • 博文数量: 356
  • 博客积分: 8284
  • 博客等级: 中将
  • 技术积分: 4580
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-15 20:25
个人简介

天行健,君子以自强不息

文章分类

全部博文(356)

文章存档

2018年(1)

2016年(4)

2015年(13)

2014年(14)

2013年(2)

2012年(25)

2011年(43)

2010年(65)

2009年(189)

分类: LINUX

2009-11-15 19:36:15

控件的几何排列-Laying Out Widgets

#include
#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(35);
    QHBoxLayout *layout=new QHBoxLayout;
    layout->addWidget(spinBox);
    layout->addWidget(slider);
   
    window->setLayout(layout);
    window->show();
    return app.exec();
}
效果如下:


如果没有  window->setLayout(layout);
效果如下:

如代码改为:
#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(35);
    QHBoxLayout *layout=new QHBoxLayout;
    layout->addWidget(spinBox);
    layout->addWidget(slider);
   
   
    window->show();
    window->setLayout(layout);
    return app.exec();
}
效果如下:

可见,写代码时的一点细微差别影响之大!
阅读(996) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~