Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5699814
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: C/C++

2007-01-02 19:56:13

下面是一个滑动条的例子:
#include
#include
#include
#include
#include
#include
#include
#include

class SpinSlider:public QWidget
{
    public:
        SpinSlider(QWidget *parent=0);
};
SpinSlider::SpinSlider(QWidget *parent):QWidget(parent)
{
    QSpinBox *spinbox = new QSpinBox();
    spinbox->setRange(0,100);
    spinbox->setValue(0);

    QSlider *slider = new QSlider(Qt::Horizontal);
    slider->setRange(0,100);
    slider->setValue(0);

    connect(spinbox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int)));

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(spinbox);
    layout->addWidget(slider);
    setLayout(layout);
}

class MyWidget:public QWidget
{
    public:
        MyWidget(QWidget *parent = 0);
};

MyWidget::MyWidget(QWidget *parent):QWidget(parent)
{
    QPushButton *quit = new QPushButton(tr("Quit!"));
    quit->setFont( QFont("Times",18,QFont::Bold) );
   
    SpinSlider *spinslider = new SpinSlider;

    connect(quit,SIGNAL(clicked()),qApp,SLOT(quit()));

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(quit);
    layout->addWidget(spinslider);
    setLayout(layout);

    setWindowTitle("Quit SpinBox Slider");
}

int main(int argc,char **argv)
{
    QApplication app(argc,argv);
    MyWidget widget;
    widget.show();

    return app.exec();
}

设计SpinSlider类封装了SpinBox和Slider就是输入框和滑动条,它们是安照横向排列;SpinSlider和quit进行纵向排列。
阅读(2708) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~