Results 1 to 3 of 3

Thread: Synchronize three listwidget scrollbars?

  1. #1
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Synchronize three listwidget scrollbars?

    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/5918...wo-QListWidget

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

    Qt Code:
    1. connect(ui->userListWidget->verticalScrollBar(), SIGNAL(&QAbstractSlider::valueChanged()),
    2. this, SLOT(syncronizeScrollBars()));
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Synchronize three listwidget scrollbars?

    You are mixing two styles of connect(): using the SIGNAL() and SLOT() macros, or direct function references.
    Qt Code:
    1. connect(ui->slider1, SIGNAL(valueChanged(int)), ui->slider2, SLOT(setValue(int)));
    2. connect(ui->slider1, SIGNAL(valueChanged(int)), ui->slider3, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 
    Or something like
    Qt Code:
    1. connect(ui->slider1, &QSlider::valueChanged, ui->slider2, &QSlider::setValue);
    2. connect(ui->slider1, &QSlider::valueChanged, ui->slider3, &QSlider::setValue);
    To copy to clipboard, switch view to plain text mode 

    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.

  3. The following user says thank you to ChrisW67 for this useful post:

    Leutzig (5th May 2016)

  4. #3
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Synchronize three listwidget scrollbars?

    Thanks ChrisW67, that was surprisingly simple!

Similar Threads

  1. synchronize scrollbar
    By jackajack01 in forum Qt Programming
    Replies: 1
    Last Post: 7th September 2012, 00:38
  2. synchronize QWebPage
    By januszmk in forum Newbie
    Replies: 0
    Last Post: 4th August 2012, 12:45
  3. Synchronize with Editor
    By dwarnold45 in forum Newbie
    Replies: 0
    Last Post: 31st March 2010, 05:40
  4. synchronize threads
    By weixj2003ld in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2009, 08:08
  5. synchronize two QSplitters
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2007, 18:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.