How to connect a Qslider to a QPoint for changing the point position in a QScatterSeries?
-
Hello, everyone, I wanna to change the position of a point (which was defined by QPoint) by using a slide bar (based on Qslider).
I want the point position in x-axes changed when the slidebar changed.
how can i do?really appreciate it
-
@amir.sanaat The slider has doc.qt.io/qt-5/qabstractslider.html#sliderMoved signal. Connect a slot to it and update the x coordinate of your point accordingly.
-
Dear @jsulm
I really approciate it for your reply.
As I am not a Qt expert, I couldn't understand your answer.
Actually, I create a slider called slider1 and point (315,4) in QScatterSeriesQScatterSeries *series1 = new QScatterSeries();
series1->setName("power");
series1->append(315,4);
QSlider *slider1 = new QSlider(Qt::Horizontal,0);how can I connect these to by signal and slot?
-
@amir.sanaat If you're not familiar with signals/slots then you should first learn how they work as they are one of the core concepts in Qt. See http://doc.qt.io/qt-5/signalsandslots.html
I assume here that the code you posted is located in MainWindow:MainWindow::MainWindow(...) { // You should declare series1 as member variable to be able to access it later series1 = new QScatterSeries(); series1->setName("power"); series1->append(315,4); QSlider *slider1 = new QSlider(Qt::Horizontal,0); connect(slider, &QSlider::sliderMoved, this, MainWindow::onSliderMoved); } void MainWindow::onSliderMoved(int value) { // Change here the position }