PDA

View Full Version : Synchronize three listwidget scrollbars?



Leutzig
5th May 2016, 18:33
Hi,

I need to synchronize the vertical scrollbars of three listwidget so that they all move to the same position when one scrollbar's position is changed (they all have the same number of items).

I found this question in a different post, which but I don't exactly understand the posted solution and therefore don't know how to use it.
http://www.qtcentre.org/threads/59189-Synchronizing-scrollbars-on-two-QListWidget

I understand the general idea so I tried creating my own connect like this for one of the scrollbars:



connect(ui->userListWidget->verticalScrollBar(), SIGNAL(&QAbstractSlider::valueChanged()),
this, SLOT(syncronizeScrollBars()));


I haven't implemented syncronizeScrollBars() yet, but this is where I'll set the positions of the other scrollbars to the changed scrollbars position. I somehow need to prevent a recursive loop when the other scrollbar positions are changed, but first I need to make my connect() work. I get the following message when I call the connect() above.


Object::connect: No such signal QScrollBar::&QAbstractSlider::valueChanged() in ../FlexVault/FlexVault_Qt/activitylog.cpp:20
Object::connect: (receiver name: 'ActivityLog')

Why is that? How do I fix my connect() so it will emit the valueChanged() when my scrollbar's position changes?

// Leutzig

ChrisW67
5th May 2016, 21:46
You are mixing two styles of connect(): using the SIGNAL() and SLOT() macros, or direct function references.


connect(ui->slider1, SIGNAL(valueChanged(int)), ui->slider2, SLOT(setValue(int)));
connect(ui->slider1, SIGNAL(valueChanged(int)), ui->slider3, SLOT(setValue(int)));
Or something like


connect(ui->slider1, &QSlider::valueChanged, ui->slider2, &QSlider::setValue);
connect(ui->slider1, &QSlider::valueChanged, ui->slider3, &QSlider::setValue);

You should be able to connect all the sliders directly to each other without a recursion issue: the signals are only issued when the new value is different from the existing value.

Leutzig
5th May 2016, 22:27
Thanks ChrisW67, that was surprisingly simple! :)