本文主要是介绍Qt之QSlider和QProgressBar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt之QSlider和QProgressBar
实验结果
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);connect(ui->dial,&QDial::valueChanged,this,&Widget::do_valueChanged);connect(ui->horizontalScrollBar,&QScrollBar::valueChanged,this,&Widget::do_valueChanged);connect(ui->horizontalSlider,&QSlider::valueChanged,this,&Widget::do_valueChanged);
}Widget::~Widget()
{delete ui;
}void Widget::do_valueChanged(int value)
{ui->progressBar->setValue(value);
}void Widget::on_checkTextVisable_clicked(bool checked)
{ui->progressBar->setTextVisible(checked);
}void Widget::on_checkiverterapper_clicked(bool checked)
{ui->progressBar->setInvertedAppearance(checked);
}void Widget::on_radiopercentage_clicked()
{ui->progressBar->setFormat("%p%");
}void Widget::on_radioButton_2_clicked()
{ui->progressBar->setFormat("%v");
}
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();
private slots:void do_valueChanged(int value);void on_checkTextVisable_clicked(bool checked);void on_checkiverterapper_clicked(bool checked);void on_radiopercentage_clicked();void on_radioButton_2_clicked();private:Ui::Widget *ui;
};#endif // WIDGET_H
这篇关于Qt之QSlider和QProgressBar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!