Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3217317
  • 博文数量: 1805
  • 博客积分: 135
  • 博客等级: 入伍新兵
  • 技术积分: 3345
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-19 20:01
文章分类

全部博文(1805)

文章存档

2017年(19)

2016年(80)

2015年(341)

2014年(438)

2013年(349)

2012年(332)

2011年(248)

分类:

2011-08-31 23:46:09

原文地址:滑动条的使用 作者:CUDev

下面是一个滑动条的例子:
#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进行纵向排列。
阅读(748) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~