Skip to content

Commit

Permalink
Add slot for counter button click handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Dec 26, 2024
1 parent 052166f commit ea35aed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
39 changes: 20 additions & 19 deletions examples/Examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,9 @@ QGroupBox* Examples::createProgressBarCounter()
startStop.click();
}
});
QObject::connect(
&startStopButtonCounter_, &QPushButton::clicked, &progressBarCounter_,
[&timer = progressCounterTimer_, &startStop = startStopButtonCounter_,
&bar = progressBarCounter_]()
{
const bool running = bar.isRunning();
if (running)
{
bar.stop();
timer.stop();
}
else
{
bar.start();
timer.start();
}
startStop.setText(
(running ? QStringLiteral("start") : QStringLiteral("stop")));
});
QObject::connect(&startStopButtonCounter_, &QPushButton::clicked, this,
&Examples::counterButtonClicked);

return wrapProgressBar(QStringLiteral("Counter progress bar"),
&progressBarCounter_, &startStopButtonCounter_);
}
Expand Down Expand Up @@ -214,3 +198,20 @@ void Examples::infiniteButtonClicked()
startStopButtonInfinite_.setText(QStringLiteral("stop"));
}
}

void Examples::counterButtonClicked()
{
const bool running = progressBarCounter_.isRunning();
if (running)
{
progressBarCounter_.stop();
progressCounterTimer_.stop();
startStopButtonCounter_.setText(QStringLiteral("start"));
}
else
{
progressBarCounter_.start();
progressCounterTimer_.start();
startStopButtonCounter_.setText(QStringLiteral("stop"));
}
}
2 changes: 2 additions & 0 deletions examples/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ private slots:
void filterStringsValuesChanged(QStringList bannedItems);

void infiniteButtonClicked();

void counterButtonClicked();
};

0 comments on commit ea35aed

Please sign in to comment.