Create the project QSliderTest to
realize the function: click the button: reset the sliding box, slide the sliding box, and display the moving distance
. Add a horizontal and a vertical sliding box to the ui interface, and a button.
Add a signal slot
. Add code in QSliderTest.h
#pragma once
#include <QtWidgets/QWidget>
#include "ui_QSliderTest.h"
class QSliderTest : public QWidget
{
Q_OBJECT
public:
QSliderTest(QWidget *parent = Q_NULLPTR);
public slots:
void Move(int);
void Change(int);
void Press();
void Rel();
void Click();
private:
Ui::QSliderTestClass ui;
};
Add code in QSliderTest.cpp
#include "QSliderTest.h"
#include <QDebug>
QSliderTest::QSliderTest(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}
//拖到滑块条
void QSliderTest::Move(int v)
{
qDebug() << "Move" << v;
}
//点击,拖动,直接设置
void QSliderTest::Change(int v)
{
qDebug() << "Change" << v;
}
//点击滑块
void QSliderTest::Press()
{
qDebug() << "Press" << ui.horizontalSlider->value();
}
void QSliderTest::Rel()
{
qDebug() << "Rel"<< ui.horizontalSlider->value();
}
void QSliderTest::Click()
{
int v=ui.horizontalSlider->value() + 10;
ui.horizontalSlider->setValue(300);
}
Set the slot function in the ui interface
Set the console output
Run the program
August 15, 2020 00:06:39