Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add RangeSlider testing code #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Qt-RangeSlider
Implement range slider in Qt<br>
Here is the demo:<br>
![image](https://github.com/ThisIsClark/Qt-RangeSlider/blob/master/demo.gif)<br>
![image](https://github.com/hellowilman/Qt-RangeSlider/blob/master/demo.gif)<br>
## How to use
1. Import RangeSlider.cpp & RangeSlider.h to your project.
2. Add a widget in Qt Designer.
3. Right click this widget to promote it to RangeSlider.
4. Now you can use this RangeSlider in your code.
4. Now you can use this RangeSlider in your code.
1 change: 1 addition & 0 deletions RangeSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void RangeSlider::mouseMoveEvent(QMouseEvent* aEvent)
void RangeSlider::mouseReleaseEvent(QMouseEvent* aEvent)
{
Q_UNUSED(aEvent);
emit slidingFinished();

mFirstHandlePressed = false;
mSecondHandlePressed = false;
Expand Down
1 change: 1 addition & 0 deletions RangeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class RangeSlider : public QWidget
void lowerValueChanged(int aLowerValue);
void upperValueChanged(int aUpperValue);
void rangeChanged(int aMin, int aMax);
void slidingFinished();

public slots:
void setLowerValue(int aLowerValue);
Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,46 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);

ui->widget->setMinimum(0);
ui->widget->setMaximum(999);

ui->label_1->setText(QString::number(0));
ui->label_2->setText(QString::number(999));
ui->label_3->setText("Current Value: " + QString::number(0) + "-" + QString::number(999));

connect(ui->widget,SIGNAL(lowerValueChanged(int)), this, SLOT(slog_RangeSlider_lower_changed(int)));
connect(ui->widget,SIGNAL(upperValueChanged(int)), this, SLOT(slog_RangeSlider_upper_changed(int)));
connect(ui->widget, SIGNAL(rangeChanged(int,int)), this, SLOT(slog_RangeSlider_changevalue(int,int)));
connect(ui->widget, SIGNAL(slidingFinished()), this, SLOT(slog_RangeSlider_slidingfinish()));
}


MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::slog_RangeSlider_lower_changed(int value)
{
ui->label_1->setText(QString::number(value));
}

void MainWindow::slog_RangeSlider_upper_changed(int value)
{
ui->label_2->setText(QString::number(value));
}

void MainWindow::slog_RangeSlider_changevalue(int v1, int v2)
{
ui->label_3->setText("Current Value: " + QString::number(v1) + "-" + QString::number(v2));

}

void MainWindow::slog_RangeSlider_slidingfinish()
{
int v1 = ui->widget->GetLowerValue();
int v2 = ui->widget->GetUpperValue();

ui->label_3->setText("Current Value: " + QString::number(v1) + "-" + QString::number(v2));
}
5 changes: 5 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void slog_RangeSlider_lower_changed(int value);
void slog_RangeSlider_upper_changed(int value);
void slog_RangeSlider_changevalue(int v1,int v2);
void slog_RangeSlider_slidingfinish();

private:
Ui::MainWindow *ui;
Expand Down
65 changes: 53 additions & 12 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,68 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>RangeSlider</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="RangeSlider" name="widget" native="true">
<property name="geometry">
<rect>
<x>40</x>
<y>70</y>
<width>311</width>
<height>80</height>
</rect>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="RangeSlider" name="widget" native="true"/>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background:rgb(206, 224, 240)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_1">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>22</height>
<height>26</height>
</rect>
</property>
</widget>
Expand Down