I have a slider, and I aim to configure it so that upon a left-click, the slider value is captured, and subsequent actions can be taken based on that value. However, in my current implementation, I've noticed that when I click on the slider, it continues to move even after the mouse click is released. How can I prevent the slider from moving once it has been clicked?Here is the code I have:
bool eventFilter(QObject* /*unused*/, QEvent* event) override { if (event->type() == QEvent::MouseButtonRelease) { auto* mouseEvent = dynamic_cast<QMouseEvent*>(event); if (mouseEvent->button() == Qt::LeftButton && !slider_->isSliderDown()) { auto normalized_position = double(mouseEvent->pos().x()) / double(slider_->width()); auto value = slider_->minimum() + ((slider_->maximum() - slider_->minimum()) * normalized_position); slider_->setValue(static_cast<int>(value)); slider_->sliderReleased(); slider_->setSliderDown(false); return true; } } return false; }